Reply to Re: why does 69.99*100=6998?

Your name:

Reply:


Posted by Jerry Stuckle on 02/01/08 16:12

The Natural Philosopher wrote:
>
> The question says it all.
>
> I have an input box, which I fill in with a price.
> IOt gets passed to the main form as a variable, then shoved into an SQL
> field vue a print '%d' statement where the argument is $price*100.
>
> For some reaosn, this particular value goes to 6998.
>
> If I update hee database manually to 6999, it displays as 69.99.
>
> If I enter 69.999 it updates as 6999..not 69999
>
> I must be doing something really dumb here..
>

Because floating point numbers are almost always not exact. The .99
cannot be represented exactly in floating point - it's a repeating
number, like 1/3 is in decimal.

I store prices in cents (i.e. 6999) then display them as dollars.

Alternatively, you could use the DECIMAL datatype in your database.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[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

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