Reply to Re: [PHP] Help. Floats turning into really small numbers? x.xxxxxxxxxxxxxxxxxxxxxxE-xx

Your name:

Reply:


Posted by Rasmus Lerdorf on 04/05/05 19:36

Anthony Tippett wrote:
> I'm having trouble figuring out why subtraction of two floats are giving
> me a very small number. I'm thinking it has something to do with the
> internals of type casting, but i'm not sure. If anyone has seen this or
> can give me some suggestions, please.
>
> I have 2 variables that go through a while loop and are
> added/subtracted/ multipled. InvAmt and InvPay are shown as
> floats but when they are subtracted, they give me a really small
> number
>
> // code
> var_dump($InvAmt);
> var_dump($InvPay);
> var_dump($InvAmt-$InvPay);
>
> // output
> float(18.49)
> float(18.49)
> float(2.1316282072803E-14)

Computers are not able to represent floating point numbers precisely.
If you are doing financial stuff I would suggest using integer math and
working completely in pennies.

-Rasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация