开发者

php nearest ten-th value

I am getting a max value through value. It开发者_Python百科 can be any digit (whole number). I want it to take to next tenth-value, using PHP

Example:

If value is 66, then I need value 70

If value is 6, then I need value 10

If value is 98, then I need value 100


This is an arithmetic problem:

y = ceil(x / 10) * 10

If you’re looking just for the nearest decade, use round instead.


$num = 66;

    $val = ceil($num / 10) * 10;

echo $val;

Thanks.


or

echo round(66,-1);

up to 30 characters

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜