WordPress at a glance

number_format_i18n() WP 1.0

Convert float number to format based on the locale.

Basis of: size_format()
1 time — 0.000034 sec (very fast) | 50000 times — 0.06 sec (speed of light) | PHP 7.1.2, WP 4.7.4
Hooks from the function
Return

String. Converted number in string format.

Usage

number_format_i18n( $number, $decimals );
$number(float) (required)
The number to convert based on locale.
$decimals(int)
Precision of the number of decimal places.

Notes

  • Global. WP_Locale. $wp_locale WordPress date and time locale object.

Changelog

Since 2.3.0 Introduced.

Code of number_format_i18n() WP 5.7.2

<?php
function number_format_i18n( $number, $decimals = 0 ) {
	global $wp_locale;

	if ( isset( $wp_locale ) ) {
		$formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] );
	} else {
		$formatted = number_format( $number, absint( $decimals ) );
	}

	/**
	 * Filters the number formatted based on the locale.
	 *
	 * @since 2.8.0
	 * @since 4.9.0 The `$number` and `$decimals` parameters were added.
	 *
	 * @param string $formatted Converted number in string format.
	 * @param float  $number    The number to convert based on locale.
	 * @param int    $decimals  Precision of the number of decimal places.
	 */
	return apply_filters( 'number_format_i18n', $formatted, $number, $decimals );
}

From tag: localize (l10n i18n Internationalization localization)

More from category: Formatting

No comments
    Log In