id summary reporter owner description type status priority milestone component version severity resolution keywords cc focuses
10555 number_format_i18n function doesn't check if the number is float or not before doing the formating chombium nbachiyski "Hi,
Problem description:
I've noticed that there are problems in representation of decimal numbers. The number representation is defined by the following three values in the wordpress.pot translation file: number_format_decimals, number_format_decimal_point and number_format_thousands_sep.
In the Macedonian language translation of wordpress.pot which I
maintain, I've set this values to:[[BR]]
number_format_decimals = 3[[BR]]
number_format_decimal_point = ,[[BR]]
number_format_thousands_sep = .[[BR]]
This means that the proper decimal number representation would be 1.234,567[[BR]]
I've noticed that all the numbers including integers are shown with this format, so for example, I get ""23,000"" posts on the dashboard instead of ""23"".[[BR]]
I can fix this behavior by setting:
number_format_decimals = 0
in the translation, but if a floating point number has to be formated it will be truncated to its integer part.
This way all the floating point numbers are not formated correctly, but as I was told by Nikolay Bachiyski, this is the safe way to solve this issue because this function is called only with integers.
I dig trough the code of wp 2.8.3 and I've noticed that the problematic function is number_format_i18n located in wp-includes/functions.php
This function is the only place where php number_format function is
called with the parameters from the translation file.
Solution:
The function number_format_i18n has to be patched so that first it checks what kind of number should be formated (integer or float) and then to do the formating. This means it has to set the correct number of decimal places before calling the php number_format function.
This can be done by adding the line:
{{{
if (!is_float($number)) $decimals = 0;
}}}
after setting the number of decimals, the line:
{{{
$decimals = ( is_null( $decimals ) ) ? $wp_locale->number_format['decimals'] : intval( $decimals );
}}}
The proposed patch simply checks if the number which has to be formated is not float and if that is the case it sets the number of decimals to 0 ($decimals = 0)
I don't know if the file: wp-content/plugins/akismet/akismet.php has to be patched as well because it redeclares the number_format_i18n function if it doesn't exist. I see that the function is called with one parameter in this file, which means decimals = 0.
The diff file of wp-includes/functions.php is in the attachment.
Jovan" defect (bug) closed normal 3.0 I18N 2.9 normal fixed has-patch dev-feedback