RE: [PHP-DB] number_format problem
| From: | Aleks @ USA.net | Date: | Wed, 05 Nov 2003 16:16:34 +0000 |
| Subject: | RE: [PHP-DB] number_format problem | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-31430@lists.php.net to get a copy of this message | ||
Great answer... One question though, how would you convert it back to
X,xxx.00 format??
Thanks
Aleks
-----Original Message-----
From: Peter Beckman [mailto:beckman@purplecow.com]
Sent: Wednesday, November 05, 2003 10:48 AM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] number_format problem
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/
---------------------------------------------------------------------------
--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php