How do I arredondo the third decimal place in php?
I need a help, I have following problem, I need to round the third decimal place up, how do I do it?
EX:
From 3.49 converts to 3.50 From 3.48 converts to 3.50 From 3.43 converts to 3.50 From 3.42 converts to 3.50
When I use function round
it converts to 4.00
Can anyone help me?
2
1 answers
You have to use the second argument of this function round
which is exactly the number of decimal places, the precision.
Example:
echo round(3.425); // 3
echo round(3.425 , 1); // 3.4
echo round(3.425 , 2); // 3.43
echo round(3.425 , 3); // 3.425
To convert to the style of ceil
but with decimal places you can do like this:
function ceil_dec($val, $dec) {
$pow = pow(10, $dec);
return ceil($pow * $val) / $pow;
}
echo ceil_dec(3.43, 1); // 3.5
8
Author: Sergio, 2017-07-06 15:05:04