返回介绍

zeroise()

发布于 2017-09-11 13:13:40 字数 2720 浏览 1250 评论 0 收藏 0

zeroise( int $number,  int $threshold )

Add leading zeros when necessary.


description

If you set the threshold to ‘4’ and the number is ’10’, then you will get back ‘0010’. If you set the threshold to ‘4’ and the number is ‘5000’, then you will get back ‘5000’.

Uses sprintf to append the amount of zeros based on the $threshold parameter and the size of the number. If the number is large enough, then no zeros will be appended.


参数

$number

(int) (Required) Number to append zeros to if not greater than threshold.

$threshold

(int) (Required) Digit places number needs to be to not have zeros added.


返回值

(string) Adds leading zeros to number if needed.


源代码

File: wp-includes/formatting.php

function zeroise( $number, $threshold ) {
	return sprintf( '%0' . $threshold . 's', $number );
}

更新日志

Versiondescription
0.71Introduced.

相关函数

Used By

  • wp-admin/export.php: export_date_options()
  • wp-admin/includes/class-wp-list-table.php: WP_List_Table::months_dropdown()
  • wp-admin/includes/template.php: touch_time()
  • wp-admin/includes/media.php: media_upload_library_form()
  • wp-includes/formatting.php: antispambot()
  • wp-includes/general-template.php: get_calendar()
  • wp-includes/general-template.php: wp_title()
  • wp-includes/class-wp-locale.php: WP_Locale::get_month()
  • wp-includes/link-template.php: get_month_link()
  • wp-includes/link-template.php: get_day_link()
  • Show 5 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

    Leading zeros on number of comments

    $comno = get_comments_number();
    echo zeroise( $comno, 2 );
    

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

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

发布评论

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