diff --git a/plugins/woocommerce-admin/client/lib/number/index.js b/plugins/woocommerce-admin/client/lib/number/index.js index cee7f742120..1cc17027cbe 100644 --- a/plugins/woocommerce-admin/client/lib/number/index.js +++ b/plugins/woocommerce-admin/client/lib/number/index.js @@ -8,7 +8,7 @@ const number_format = require( 'locutus/php/strings/number_format' ); /** * Formats a number using site's current locale * - * @see https://locutus.io/php/strings/number_format/ + * @see http://locutus.io/php/strings/number_format/ * @param {Number|String} number number to format * @param {int|null} [precision=null] optional decimal precision * @returns {?String} A formatted string. @@ -25,21 +25,11 @@ export function numberFormat( number, precision = null ) { const decimalSeparator = get( wcSettings, [ 'currency', 'decimal_separator' ], '.' ); const thousandSeparator = get( wcSettings, [ 'currency', 'thousand_separator' ], ',' ); + precision = parseInt( precision ); - if ( null === precision ) { - const [ numberNoDecimals, decimals ] = number.toString().split( '.' ); - const formattedNumber = number_format( - numberNoDecimals, - 0, - decimalSeparator, - thousandSeparator - ); - - if ( decimals ) { - return formattedNumber + decimalSeparator + decimals; - } - - return formattedNumber; + if ( isNaN( precision ) ) { + const [ , decimals ] = number.toString().split( '.' ); + precision = decimals ? decimals.length : 0; } return number_format( number, precision, decimalSeparator, thousandSeparator );