2013-02-18 36 views

回答

6

使用round()功能與-2精度值,

round($number, -2); 

Codepad Viper Demo.

+0

完美,最後一個問題:我怎麼能做到這一點同樣每隔50計數?但高達1000例如。 232 = 250,264 = 300,783 = 800,721 = 750 ...如果數字大於「1000」,則使用第一種方法。 – 2013-02-18 11:56:34

+0

在這種情況下,我認爲你需要使用ghost建議的方法,比如'echo round(235/50)* 50;' – Rikesh 2013-02-18 12:01:57

0

你可以通過將數字除以100並使用round函數來實現。

0
<?php 

    function foo($number, $d) 
    { 
     return round($number/$d) * $d; 
    } 

    echo foo(1527, 100) . "\n"; 
    echo foo(12081, 100) . "\n"; 

?>