tags:

views:

25

answers:

2

I have an excel sheet that has number in cell that are formatted as #,##0.00.. Now, when I try to calculate those values using php round() function as round($number,2) , sometimes, the values are not exactly same, difference comes in the 2nd decimal place. What can be the problem? Has anyone experienced the same?

A: 

I'm guessing here, but Excel may well round money in a certain direction as opposed to rounding it up or down about .5, which you're not doing with PHP. I'd presume it rounds down, change it to floor($number * 100) / 100 and see if you get the same answers (that's rounding the number down on the second decimal place, floor() doesn't support a precision parameter).

46Bit
A: 

what version of php are you using? older versions have non-standard rounding routine, prior to 5.2.7 they wouldnt always give the 'expected' results:

http://us3.php.net/manual/en/function.round.php

Ben Reisner