number_format_i18n

函数
number_format_i18n ( $number, $decimals = 0 )
参数
  • (float) $number The number to convert based on locale.
    Required:
  • (int) $decimals Optional. Precision of the number of decimal places. Default 0.
    Required:
返回值
  • (string) Converted number in string format.
定义位置
相关方法
get_post_format_link_post_format_linkget_post_format_stringsize_formattimer_float
引入
2.3.0
弃用
-

number_format_i18n: 这个函数根据当前地区的千位分隔符和小数点的约定来格式化一个数字。它被用来确保不同语言和地区的数字格式的一致性。

将浮点数转换为基于当地语言的格式。

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 );
}

常见问题

FAQs
查看更多 >