[development] Converting floats stored in scientific notation back to decimals

Wim Leers work at wimleers.com
Mon Nov 5 19:39:42 UTC 2007

On Nov 5, 2007, at 20:06 , Walt Daniels wrote:

> decimal numbers do not an exact binary representation (in general),  
> e.g.
> 1/3, within the finite field width of computers. Any time you  
> convert you
> have rounding issues which are messy at best. If your meaning of  
> decimal
> numbers is really just dollars and cents (not internationalizable)  
> with 2
> decimal places, then you should use integers (in cents) and then  
> you just
> have a formating problem.

That's exactly what I'm doing with the Money CCK field. People have  
asked for a configurable precision though (e.g. prices of houses  
don't need cents), so I'd suggest to track per field how many decimal  
that field uses. This way, you can *always* store numbers as integers.

Wim Leers  ~  http://wimleers.com/work

More information about the development mailing list