Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and Excel calculation differences

Tags:

php

excel

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.582429275152 in Excel is equal to 0,997534589570654

How to solve such issues and to have differences in calculations?

like image 974
Karolis Avatar asked Apr 07 '26 04:04

Karolis


1 Answers

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)

like image 91
mario Avatar answered Apr 09 '26 19:04

mario