zeroise()
zeroise( int $number, int $threshold ) 必要时添加前导零。 Add le…
zeroise( int $number, int $threshold )
必要时添加前导零。
Add leading zeros when necessary.
目录锚点:#说明#参数#源码#笔记
说明(Description)
如果将阈值设置为’4’,数字为’10’,则返回’0010’。如果您将阈值设置为’4’,数字为’5000’,那么您将返回’5000’。使用sprintf根据$threshold参数和数字的大小追加0的数量。如果数字足够大,则不会追加零。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $number | (int) | 如果不大于阈值,则要向其追加零的数字。 |
| $threshold | (int) | 位数数字不需要加零。 |
源码(Source)
/**
* Add leading zeros when necessary.
*
* 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.
*
* @since 0.71
*
* @param int $number Number to append zeros to if not greater than threshold.
* @param int $threshold Digit places number needs to be to not have zeros added.
* @return string Adds leading zeros to number if needed.
*/
function zeroise( $number, $threshold ) {
return sprintf( '%0' . $threshold . 's', $number );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 0.71 | wp-includes/formatting.php | 18 | 17 |
笔记(Notes)
注释数的前导零
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!