<?php */ echo round(3.4); //输出3 echo "<br>"; echo round(3.5); //输出4 echo "<br>"; echo round(3.6); //输出4 echo "<br>"; echo round(3.6,0); //输出4 echo "<br>"; echo round(1.95583,2); //输出1.96 echo "<br>"; echo round(1241757,-3); //输出1242000 echo "<br>"; echo round(4.045,2); //输出4.05 echo "<br>"; echo round(4.055,2); //输出4.06 //使用stdround函数代替php的round函数 ?>
<?php function stdround($num, $d=0) { return round($num + 0.0001 / pow(10, $d), $d); } echo "round(1.005,2)= ".round(1.005,2). "n "; echo "round(1.015,2)= ".round(1.015,2). "n "; echo "round(1.025,2)= ".round(1.025,2). "n "; echo "round(1.035,2)= ".round(1.035,2). "n "; echo "round(1.045,2)= ".round(1.045,2). "n "; echo "round(1.055,2)= ".round(1.055,2). "n "; echo "round(1.065,2)= ".round(1.065,2). "n "; echo "round(1.075,2)= ".round(1.075,2). "n "; echo "round(1.085,2)= ".round(1.085,2). "n "; echo "round(1.095,2)= ".round(1.095,2). "n "; echo "stdround(1.005,2)= ".stdround(1.005,2). "n "; echo "stdround(1.015,2)= ".stdround(1.015,2). "n "; echo "stdround(1.025,2)= ".stdround(1.025,2). "n "; echo "stdround(1.035,2)= ".stdround(1.035,2). "n "; echo "stdround(1.045,2)= ".stdround(1.045,2). "n "; echo "stdround(1.055,2)= ".stdround(1.055,2). "n "; echo "stdround(1.065,2)= ".stdround(1.065,2). "n "; echo "stdround(1.075,2)= ".stdround(1.075,2). "n "; echo "stdround(1.085,2)= ".stdround(1.085,2). "n "; echo "stdround(1.095,2)= ".stdround(1.095,2). "n "; $m=0.000000000000001; echo "n "; echo "round(1.005+{$m},2)= ".round(1.005+$m,2). "n "; echo "round(1.015+{$m},2)= ".round(1.015+$m,2). "n "; echo "round(1.025+{$m},2)= ".round(1.025+$m,2). "n "; echo "round(1.035+{$m},2)= ".round(1.035+$m,2). "n "; echo "round(1.045+{$m},2)= ".round(1.045+$m,2). "n "; echo "round(1.055+{$m},2)= ".round(1.055+$m,2). "n "; echo "round(1.065+{$m},2)= ".round(1.065+$m,2). "n "; echo "round(1.075+{$m},2)= ".round(1.075+$m,2). "n "; echo "round(1.085+{$m},2)= ".round(1.085+$m,2). "n "; echo "round(1.095+{$m},2)= ".round(1.095+$m,2). "n "; echo "round(1.005,2)= ".round(1.005,2). "n "; echo "round(1.015,2)= ".round(1.015,2). "n "; echo "round(1.025,2)= ".round(1.025,2). "n "; echo "round(1.035,2)= ".round(1.035,2). "n "; echo "round(1.045,2)= ".round(1.045,2). "n "; echo "round(1.055,2)= ".round(1.055,2). "n "; echo "round(1.065,2)= ".round(1.065,2). "n "; echo "round(1.075,2)= ".round(1.075,2). "n "; echo "round(1.085,2)= ".round(1.085,2). "n "; echo "round(1.095,2)= ".round(1.095,2). "n "; ?>
希望本文所述对大家的PHP程序设计有所帮助。