Is there any library function for this purpose, so I don't do it by hand and risk ending in TDWTF?
echo ceil(31497230840470473074370324734723042.6);
// Expected result
31497230840470473074370324734723043
// Prints
<garbage>
Is there any library function for this purpose, so I don't do it by hand and risk ending in TDWTF?
echo ceil(31497230840470473074370324734723042.6);
// Expected result
31497230840470473074370324734723043
// Prints
<garbage>
OK, for my high-precision Money library, which is currently on hundreds of production sites, I had to completely rewrite this bcround functionality. Nothing I found on the entire Internet was up to code.
Here's what I came up with:
This will work for you:
Basically it finds the flooy by multiplying by one with zero precision.
Then it can do ceil / round by subtracting that from the total, calling the built in functions, then adding the result back on
Edit: fixed for -ve numbers
UPDATE: See my improved answer here: How to ceil, floor and round bcmath numbers?.
These functions seem to make more sense, at least to me:
They support negative numbers and the precision argument for the bcround() function.
Some tests: