File size: 715 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { formatPrice } from 'calypso/lib/gsuite/utils/format-price';

/**
 * Computes and formats the monthly price from the specified yearly price.
 * @param {number} cost - yearly cost (e.g. '99.99')
 * @param {string} currencyCode - code of the currency (e.g. 'USD')
 * @param {string} defaultValue - value to return when the price can't be determined
 * @returns {string} - the monthly price rounded to the nearest tenth (e.g. '$8.40'), otherwise the default value
 */
export function getMonthlyPrice( cost, currencyCode, defaultValue = '-' ) {
	if ( typeof cost !== 'number' && typeof currencyCode !== 'string' ) {
		return defaultValue;
	}

	return formatPrice( cost / 12, currencyCode, { precision: 1 } );
}