Merge branch 'pr/15304'

This commit is contained in:
Mike Jolley 2017-05-30 11:56:10 +01:00
commit 7529e1ac26
2 changed files with 15 additions and 4 deletions

View File

@ -258,8 +258,11 @@ function wc_format_decimal( $number, $dp = false, $trim_zeros = false ) {
$decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
// Remove locale from string.
if ( ! is_float( $number ) ) {
$number = str_replace( wc_get_price_thousand_separator(), '', $number );
if ( ! is_float( $number ) && strval( floatval( $number ) ) !== $number ) {
// Only remove thousands if separator is not same as decimal separator.
if ( wc_get_price_thousand_separator() !== wc_get_price_decimal_separator() ) {
$number = str_replace( wc_get_price_thousand_separator(), '', $number );
}
$number = str_replace( $decimals, '.', $number );
$number = preg_replace( '/[^0-9\.,-]/', '', wc_clean( $number ) );
}

View File

@ -6,7 +6,6 @@
* @since 2.2
*/
class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
/**
* Test wc_sanitize_taxonomy_name().
*
@ -237,7 +236,16 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
$this->assertEquals( '10', wc_format_decimal( 9.9999, '', true ) );
// given string with thousands
$this->assertEquals( '99999.99', wc_format_decimal( '9,9999.99' ) );
$this->assertEquals( '99999.99', wc_format_decimal( '99,999.99' ) );
// given string with thousands in german format
update_option( 'woocommerce_price_decimal_sep', ',' );
update_option( 'woocommerce_price_thousand_sep', '.' );
$this->assertEquals( '99999.99', wc_format_decimal( '99.999,99' ) );
update_option( 'woocommerce_price_decimal_sep', '.' );
update_option( 'woocommerce_price_thousand_sep', ',' );
}
/**