I am using this
$grandtotal = round ($grandtotal, 2);
to echo my calculated grandtotal from a shopping cart, as without it i would get something like this:
27.999999997 due to decimals in the prices.
Question,
Can i count on the floating point inaccuracy to be allways somewhere in the 0.000000 area?
If it is allways such a small number rounding shouldnt be a problem and allways return the correct total right?
Or do i need a more sophisticated approach?
The store im working on will be a food delivery and it is not expected that people would order thousands of items so that inaccuracies of 0.00000002 would accumulate to 0.1.
If you use the round function throughout your calculation then there should be no problem.
I’ve written a some accounting stuff in php and used the function with no great problems.
But be sure to check the results against some good old paper&pencil calculations. 🙂