number_format_i18n

Convert float number to format based on the locale.

Description

(string) number_format_i18n( (number) $number, (int) $decimals = 0 ); 

Returns (string)

Converted number in string format.

Parameters (2)

0. $number (number)
The number to convert based on locale.
1. $decimals — Optional. (int)
Precision of the number of decimal places. Default 0.

Usage

  1. if ( !function_exists( 'number_format_i18n' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The number to convert based on locale. 
  5. $number = null; 
  6.  
  7. // Optional. Precision of the number of decimal places. Default 0. 
  8. $decimals = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = number_format_i18n($number, $decimals); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function number_format_i18n( $number, $decimals = 0 ) { 
  2. global $wp_locale; 
  3.  
  4. if ( isset( $wp_locale ) ) { 
  5. $formatted = number_format( $number, absint( $decimals ), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep'] ); 
  6. } else { 
  7. $formatted = number_format( $number, absint( $decimals ) ); 
  8.  
  9. /** 
  10. * Filters the number formatted based on the locale. 
  11. * @since 2.8.0 
  12. * @param string $formatted Converted number in string format. 
  13. */ 
  14. return apply_filters( 'number_format_i18n', $formatted );