返回介绍

number_format_i18n()

发布于 2017-09-11 09:51:56 字数 6423 浏览 1036 评论 0 收藏 0

number_format_i18n( float $number,  int $decimals )

Convert float number to format based on the locale.


description


参数

$number

(float) (Required) The number to convert based on locale.

$decimals

(int) (Optional) Precision of the number of decimal places. Default 0.


返回值

(string) Converted number in string format.


源代码

File: wp-includes/functions.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
	 *
	 * @param string $formatted Converted number in string format.
	 */
	return apply_filters( 'number_format_i18n', $formatted );
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: absint()
  • wp-includes/functions.php: number_format_i18n
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/widgets/class-wp-widget-media.php: WP_Widget_Media::display_media_state()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post()
  • wp-includes/embed.php: print_embed_comments_button()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::customize_register()
  • wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_users()
  • wp-includes/comment-template.php: get_comments_number_text()
  • wp-admin/includes/class-wp-ms-users-list-table.php: WP_MS_Users_List_Table::get_views()
  • wp-admin/includes/class-wp-screen.php: WP_Screen::render_screen_layout()
  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::get_views()
  • wp-admin/includes/deprecated.php: WP_User_Search::do_paging()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::ajax_response()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::comments_bubble()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::pagination()
  • wp-admin/includes/class-wp-ms-themes-list-table.php: WP_MS_Themes_List_Table::get_views()
  • wp-admin/includes/plugin-install.php: install_plugin_information()
  • wp-admin/includes/dashboard.php: wp_dashboard_quota()
  • wp-admin/includes/dashboard.php: wp_network_dashboard_right_now()
  • wp-admin/includes/dashboard.php: wp_dashboard_right_now()
  • wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::display_rows()
  • wp-admin/includes/template.php: wp_star_rating()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::single_row()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::get_views()
  • wp-admin/includes/media.php: media_upload_library_form()
  • wp-admin/includes/media.php: media_handle_upload()
  • wp-admin/includes/ajax-actions.php: wp_ajax_query_themes()
  • wp-admin/includes/ajax-actions.php: _wp_ajax_delete_comment_response()
  • wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment()
  • wp-admin/includes/meta-boxes.php: post_submit_meta_box()
  • wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::get_views()
  • wp-admin/includes/class-wp-terms-list-table.php: WP_Terms_List_Table::column_posts()
  • wp-admin/includes/class-wp-terms-list-table.php: WP_Terms_List_Table::column_links()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::get_views()
  • wp-includes/class-walker-category.php: Walker_Category::start_el()
  • wp-includes/class-walker-category-dropdown.php: Walker_CategoryDropdown::start_el()
  • wp-includes/category-template.php: wp_generate_tag_cloud()
  • wp-includes/pluggable.php: wp_notify_moderator()
  • wp-includes/general-template.php: paginate_links()
  • wp-includes/load.php: timer_stop()
  • wp-includes/functions.php: size_format()
  • wp-includes/admin-bar.php: wp_admin_bar_comments_menu()
  • wp-includes/admin-bar.php: wp_admin_bar_updates_menu()
  • wp-includes/ms-functions.php: wpmu_validate_blog_signup()
  • wp-includes/comment-template.php: comments_popup_link()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::enqueue_scripts()
  • Show 39 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: -1You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    
    $number = 3948;
    
    $formatted = number_format_i18n( $number );
    

    $formatted will now be something like “3,948”.

  2. Using the $decimal Parameter

    
    $number = 3948;
    
    $formatted = number_format_i18n( $number, 2 );
    

    $formatted will now be something like “3,948.00”.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文