I need to round the numbers.
46.38 >>> 46.40
46.40 >>> 46.40
46.41 >>> 46.50
I am using round($price, 1)
but this converts 46.41 to 46.40
. But i need 46.50
I need to round the numbers.
46.38 >>> 46.40
46.40 >>> 46.40
46.41 >>> 46.50
I am using round($price, 1)
but this converts 46.41 to 46.40
. But i need 46.50
2
Answers
You need
ceil
instead of round, but it does not come with precision out of the box. You need to add this functionality yourself like e.g.You can then use it as:
This will output:
3v4l code
Note: The
number_format
is added to additionally control the decimals that will be shown in the end. It is not (strictly speaking) necessary and also causes the function output to be a string rather than a float.I recommend this approach:
This produces the outputs required from the inputs given.
… or more generally, if
$precision
is the number of digits to the right of the decimal point,