Re: number_format problem

From: Date: Wed, 05 Nov 2003 16:59:35 +0000
Subject: Re: number_format problem
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-31436@lists.php.net to get a copy of this message
From: "Peter Beckman" <beckman@purplecow.com> > 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...

« previous php.db (#31436) next »