2017-08-12 48 views
-1

我期待任何小數四捨五入到下一個數字。像1.199 答案應該是或類似1.99也應該圍捕十進制到下一個數字在PHP

這是迄今爲止我發現了什麼

echo(round(1.4,0,PHP_ROUND_HALF_UP) . "<br>"); 
echo(round(-1.4,0,PHP_ROUND_HALF_UP) . "<br>"); 
//Answer = 1 
//Answer = -1 

echo(round(1.4,0,PHP_ROUND_HALF_DOWN) . "<br>"); 
echo(round(-1.4,0,PHP_ROUND_HALF_DOWN) . "<br>"); 
//Answer = 1 
//Answer = -1 

echo(round(1.4,0,PHP_ROUND_HALF_EVEN) . "<br>"); 
echo(round(-1.4,0,PHP_ROUND_HALF_EVEN) . "<br>"); 
//Answer = 1 
//Answer = -1 

echo(round(1.4,0,PHP_ROUND_HALF_ODD) . "<br>"); 
echo(round(-1.,0,PHP_ROUND_HALF_ODD)); 
//Answer = 1 
//Answer = -1 
+0

所以'1.01'也應該是2? – Qirel

+3

使用[''ceil()'](http://php.net/manual/en/function.ceil.php)函數。 –

回答

3

使用ceil

echo ceil(1.9999); // 2 
echo ceil(1.001); // 2 
4

,如果你想接下來數使用ceil

echo ceil(1.99); //Output = 2 
3
echo ceil(1.199); 

,除此之外,該