Skip to content

Commit 3f2ee78

Browse files
committed
Restore support for floating point numbers in number_format_i18n(). Fixes WordPress#10555.
git-svn-id: https://develop.svn.wordpress.org/trunk@14190 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cae7b3b commit 3f2ee78

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

wp-admin/admin-header.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
pagenow = '<?php echo $current_screen->id; ?>',
4444
typenow = '<?php if ( isset($current_screen->post_type) ) echo $current_screen->post_type; ?>',
4545
adminpage = '<?php echo $admin_body_class; ?>',
46-
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>';
46+
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
47+
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>';
4748
//]]>
4849
</script>
4950
<?php

wp-includes/functions.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
131131
* @since 2.3.0
132132
*
133133
* @param int $number The number to convert based on locale.
134-
* @param int $decimals Precision of the number of decimal places. Deprectated.
134+
* @param int $decimals Precision of the number of decimal places.
135135
* @return string Converted number in string format.
136136
*/
137-
function number_format_i18n( $number, $decimals = null ) {
137+
function number_format_i18n( $number, $decimals = 0 ) {
138138
global $wp_locale;
139139
$number = (int)$number;
140-
if ( !is_null( $decimals ) ) _deprecated_argument( __FUNCTION__, '3.0' );
141-
$formatted = number_format( $number, 0, null, $wp_locale->number_format['thousands_sep'] );
140+
$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
142141
return apply_filters( 'number_format_i18n', $formatted );
143142
}
144143

@@ -163,7 +162,7 @@ function number_format_i18n( $number, $decimals = null ) {
163162
* @param int $decimals Precision of number of decimal places. Deprecated.
164163
* @return bool|string False on failure. Number string on success.
165164
*/
166-
function size_format( $bytes, $decimals = null ) {
165+
function size_format( $bytes, $decimals = 0 ) {
167166
$quant = array(
168167
// ========================= Origin ====
169168
'TB' => 1099511627776, // pow( 1024, 4)
@@ -172,10 +171,9 @@ function size_format( $bytes, $decimals = null ) {
172171
'kB' => 1024, // pow( 1024, 1)
173172
'B ' => 1, // pow( 1024, 0)
174173
);
175-
if ( !is_null( $decimals ) ) _deprecated_argument( __FUNCTION__, '3.0' );
176174
foreach ( $quant as $unit => $mag )
177175
if ( doubleval($bytes) >= $mag )
178-
return number_format_i18n( round( $bytes / $mag ) ) . ' ' . $unit;
176+
return number_format_i18n( $bytes / $mag, $decimals ) . ' ' . $unit;
179177

180178
return false;
181179
}

wp-includes/load.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_st
219219
$mtime = explode( ' ', $mtime );
220220
$timeend = $mtime[1] + $mtime[0];
221221
$timetotal = $timeend - $timestart;
222-
$r = number_format( $timetotal, $precision );
222+
$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
223223
if ( $display )
224224
echo $r;
225225
return $r;

wp-includes/locale.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ function init() {
181181
/* translators: $thousands_sep argument for http://php.net/number_format, default is , */
182182
$trans = __('number_format_thousands_sep');
183183
$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
184+
185+
/* translators: $dec_point argument for http://php.net/number_format, default is . */
186+
$trans = __('number_format_decimal_point');
187+
$this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans;
184188

185189
// Import global locale vars set during inclusion of $locale.php.
186190
foreach ( (array) $this->locale_vars as $var ) {

0 commit comments

Comments
 (0)