Re: number_format problem

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

 



From: "Peter Beckman" <beckman@xxxxxxxxxxxxx>
> On Wed, 5 Nov 2003, Dillon, John wrote:
>
>  I use this:
>
>       $x['funds'] = (int)preg_replace("/[\$,]/","",$x['funds']);
>
>  where $x['funds'] contains something like $3,249,555.32, and the end
>  result is an int of 3249555.  I drop the cents... you want to keep 'em,
>  change "int" to "float".

I'd be careful of casting it to float. Not sure how this would work, as it
may depend upon your database, but say you casted 100 to a float, it'd be
acceptable for PHP to store it as 99.999999999. Now when you throw that into
a DECIMAL field in MySQL for example, it may only store 99.99 instead of
rounding up.

Floating point errors are a pain. Make sure you test before implementing a
solution like this.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux