c_shelswell Posted November 4, 2009 Share Posted November 4, 2009 Hi I've got a bit of a baffling problem. I'm trying quite simply to subtract two number pulled from my database. They're store in the DB as DOUBLE and the sum would equate to 0.49 - 0.49 the answer i'm getting though is: 5.55111512313E-17 I don't get it! This is working fine on my local machine but on the web server i'm not having much luck. Anyone seen a problem like this before? Quote Link to comment https://forums.phpfreaks.com/topic/180338-solved-php-subtraction-problems/ Share on other sites More sharing options...
phpknight Posted November 4, 2009 Share Posted November 4, 2009 If it is feasible for you, store them in your database as DECIMAL 9,2, and that should eliminate this problem. You *might* have to upgrade MYSQL. Quote Link to comment https://forums.phpfreaks.com/topic/180338-solved-php-subtraction-problems/#findComment-951343 Share on other sites More sharing options...
c_shelswell Posted November 4, 2009 Author Share Posted November 4, 2009 yeah i did have them as decimal before. I assumed this might be the problem so changed it. It does it both ways. Strange thing is it has been working. Unless my web hosting people have gone and changed my mysql version but it's a dedicated server so i doubt it. Quote Link to comment https://forums.phpfreaks.com/topic/180338-solved-php-subtraction-problems/#findComment-951356 Share on other sites More sharing options...
phpknight Posted November 4, 2009 Share Posted November 4, 2009 Odd. How about using number_format function to set the precision to two digits on each of them? Then, do the math and see what the result is. That might fix it. Quote Link to comment https://forums.phpfreaks.com/topic/180338-solved-php-subtraction-problems/#findComment-951372 Share on other sites More sharing options...
c_shelswell Posted November 5, 2009 Author Share Posted November 5, 2009 cheers phpKnight. The number format seems to have sorted it. Though I still think kind of strange it should have to. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/180338-solved-php-subtraction-problems/#findComment-951452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.