Re: number_format problem
| From: | Peter Beckman | Date: | Wed, 05 Nov 2003 15:48:12 +0000 |
| Subject: | Re: number_format problem | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-31426@lists.php.net to get a copy of this message | ||
On Wed, 5 Nov 2003, Dillon, John wrote:
> I want to show a number from a database in the format x,xxx.00 in a
> textfield, then if it is changed by the user I want to post the value of the
> number to a decimal field. However, once you number_format the number it
> becomes a string, and numbers like 3,379.90 give a value of 3 when posted to
> the database, which is hinted at in the notes on number_format. I suppose I
> need a string to number function - can someone tell me what this might be
> called please?
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".
Beckman
---------------------------------------------------------------------------
Peter Beckman Internet Guy
beckman@purplecow.com http://www.purplecow.com/
---------------------------------------------------------------------------