PHP and Excel calculation differences
the problem I have is that when making same calculations in PHP and in Excel I get different answers, e.g.:
PHP
bcdiv(135.248162939981, 135.582429275152, 15)
is equal to 0.997534589571912
while performing the 135.248162939981 / 135.58242开发者_开发百科9275152
in Excel is equal to 0,997534589570654
How to solve such issues and to have differences in calculations?
bcdiv
performs an arbitrary precision calculation. Much unlike Excel, which does an ordinary floating point division.
To get a similar result in PHP just do it alike:
$r = 135.248162939981 / 135.582429275152;
That being said, the results will never be identical. Floating point calculations are inexcat by nature, furthered by display variations in programming languages and applications. http://en.wikipedia.org/wiki/Precision_(computer_science)
精彩评论