satish.mumbai Posted October 28, 2010 Share Posted October 28, 2010 Hello everyone, Here's something that seems very simple, but has been bothering me for the past few hours ! The following code in php $a = 62745.15; $b = 64293.6; $c = 1548.45; $d = $b - $a - $c; var_dump($a); var_dump($b); var_dump($c); var_dump($d); gives the following output : float(62745.15) float(64293.60) float(1548.45) float(-2.955857780762E-12) My questions : 1. Why does the value of $d not simply come to "float(0)" ?? 2. What can I do to get the value of "float(0)" for the calculation as shown in the code above ? Thanks in advance for all your replies. regards, Satish. Link to comment https://forums.phpfreaks.com/topic/217113-help-with-float-numbers-in-php/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 28, 2010 Share Posted October 28, 2010 Please read the big pink WARNING at this link - http://www.php.net/manual/en/language.types.float.php Link to comment https://forums.phpfreaks.com/topic/217113-help-with-float-numbers-in-php/#findComment-1127610 Share on other sites More sharing options...
satish.mumbai Posted October 28, 2010 Author Share Posted October 28, 2010 Hi, Thanks for your reply.... I did read that warning... but somehow i could not make much of it.... can you help me please ? what other options to I have for this kind of calculation ? thanks, Satish. Link to comment https://forums.phpfreaks.com/topic/217113-help-with-float-numbers-in-php/#findComment-1127611 Share on other sites More sharing options...
PFMaBiSmAd Posted October 28, 2010 Share Posted October 28, 2010 That warning contains a link to BC math functions that don't suffer from floating point conversion errors (because the numbers are operated on as BCD digits.) Link to comment https://forums.phpfreaks.com/topic/217113-help-with-float-numbers-in-php/#findComment-1127616 Share on other sites More sharing options...
satish.mumbai Posted October 28, 2010 Author Share Posted October 28, 2010 Hi, Thanks again for your reply.... unfortunately, the server i am working on does not have BCMath enabled. could you suggest any other workaround to this problem ? thanks, Satish. Link to comment https://forums.phpfreaks.com/topic/217113-help-with-float-numbers-in-php/#findComment-1127675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.