Learn php:Rounding and Formatting Numbers

2007-11-01 20:53 来源: 本站 作者:phpma 网友评论 0 条 浏览次数 1

learn php:Rounding and Formatting NumbersPHPMA.COM

Round () - Rounding Numbers

The PHP function round () is used to round numbers up or down based on their value (Any decimal .5 or above is rounded up, anything under .5 is rounded down.) You can specify how many decimals you would like the number rounded to. It is phrased as round ( number, optional_decimals ) If left unspecified, by default it will round to the nearest whole number. You can use negative numbers when specifying the optional_decimals, for example -1 would round to the nearest 10, -2 would round to the nearest 100, etc. PHPMA.COM
<?php
echo round(3.14159265);
// Value would be 3

echo round(3.9);
// Value would be 4

echo round(3.14159265, 3);
// Value would be 3.142

echo round(314159, -100);
// Value would be 314100
?> PHPMA.COM

上一篇:PHP MySQL Tutori..    下一篇:What is PHP?英文..

相关主题:

网友评论