Re: Converting floats to ints with intval

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2010-05-06 at 11:40 +0100, Paul Waring wrote:

> Ashley Sheridan wrote:
> > It's part of the rounding problem you get with most languages out there.
> > Why can't you compare the floating point values though? Currency should
> > only have one decimal place anyway.
> 
> You can't compare floating point values because if you have, for 
> example, a user-entered value of '37.12' and add that to '0.18' it won't 
> necessarily be equal to '37.30'.
> 
> Currency must have two decimal places, otherwise how would you represent 
> five pounds and sixteen pence (£5.16) for example?
> 
> -- 
> Paul Waring
> http://www.pwaring.com
> 


Sorry, I misread that as decimal point!

Why don't you store them as integer values and add in the decimal point
with something like sprintf() afterwards? Store the values as pence and
then you won't have any rounding problems.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux