状态 草稿
Todo Proof read
官方最后更新时间 2008/05/01 20:31

数字辅助函数

提供对整数数字进行舍入(比如,四舍无入)的方法。

方法

round()

num::round() 接受两个参数。范围里的,被进行舍入的整数。作为舍入的分界数。默认为四舍五入。

实例

// 提供一个数字数组:$numbers = array(1,3,5,9,99,999);
<p>Rounding numbers to nearest 5</p>
<?php foreach ($numbers as $number): ?>
	<p>Round <?php echo $number ?> to <?php echo num::round($number, 5) ?> </p>
<?php endforeach ?>

返回结果:

<p>Rounding numbers to nearest 5</p>
	<p>Round 1 to 0 </p>
	<p>Round 3 to 5 </p>
	<p>Round 5 to 5 </p>
 
	<p>Round 9 to 10 </p>
	<p>Round 99 to 100 </p>
	<p>Round 999 to 1000 </p>
helpers/num.txt · 最后更改: 2008/09/23 22:35 由 icyleaf