RE: number_format problem

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

 



 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@xxxxxxxxxxxxx] 
Sent: Wednesday, November 05, 2003 10:48 AM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  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@xxxxxxxxxxxxx                             http://www.purplecow.com/
---------------------------------------------------------------------------

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

-- 
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