[PHP-DB] number_format problem

2003-11-05 Thread Dillon, John
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?

Regards,

John








































   http://www.cantor.com
CONFIDENTIAL: This e-mail, including its contents and attachments, if any, are 
confidential. If you are not the named recipient please notify the sender and 
immediately delete it. You may not disseminate, distribute, or forward this e-mail 
message or disclose its contents to anybody else. Copyright and any other intellectual 
property rights in its contents are the sole property of Cantor Fitzgerald.
 E-mail transmission cannot be guaranteed to be secure or error-free. The sender 
therefore does not accept liability for any errors or omissions in the contents of 
this message which arise as a result of e-mail transmission.  If verification is 
required please request a hard-copy version.
 Although we routinely screen for viruses, addressees should check this e-mail and 
any attachments for viruses. We make no representation or warranty as to the absence 
of viruses in this e-mail or any attachments. Please note that to ensure regulatory 
compliance and for the protection of our customers and business, we may monitor and 
read e-mails sent to and from our server(s). 

For further important information, please read the  Important Legal Information and 
Legal Statement at http://www.cantor.com/legal_information.html

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread jeffrey_n_Dyke

could you cast as a float/double before inserting?  $number = (double)
$string;

don't know what would happen to the comma, but i assume it would just get
removed??

just a guess/thought
Jeff


   
 
  Dillon, John   
 
  [EMAIL PROTECTED]To:   [EMAIL PROTECTED]
   
  o.ukcc: 
 
   Subject:  [PHP-DB] number_format 
problem 
  11/05/2003 10:29 
 
  AM   
 
   
 
   
 




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?

Regards,

John








































   http://www.cantor.com
CONFIDENTIAL: This e-mail, including its contents and attachments, if any,
are confidential. If you are not the named recipient please notify the
sender and immediately delete it. You may not disseminate, distribute, or
forward this e-mail message or disclose its contents to anybody else.
Copyright and any other intellectual property rights in its contents are
the sole property of Cantor Fitzgerald.
 E-mail transmission cannot be guaranteed to be secure or error-free.
 The sender therefore does not accept liability for any errors or
 omissions in the contents of this message which arise as a result of
 e-mail transmission.  If verification is required please request a
 hard-copy version.
 Although we routinely screen for viruses, addressees should check this
 e-mail and any attachments for viruses. We make no representation or
 warranty as to the absence of viruses in this e-mail or any
 attachments. Please note that to ensure regulatory compliance and for
 the protection of our customers and business, we may monitor and read
 e-mails sent to and from our server(s).

For further important information, please read the  Important Legal
Information and Legal Statement at
http://www.cantor.com/legal_information.html

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread Peter Beckman
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
[EMAIL PROTECTED] http://www.purplecow.com/
---

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



RE: [PHP-DB] number_format problem

2003-11-05 Thread Aleks @ USA.net
 Great answer... One question though, how would you convert it back to 
X,xxx.00 format??

Thanks

Aleks

-Original Message-
From: Peter Beckman [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 05, 2003 10:48 AM
To: [EMAIL PROTECTED]
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
[EMAIL PROTECTED] 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



RE: [PHP-DB] number_format problem

2003-11-05 Thread Peter Beckman
On Wed, 5 Nov 2003, Aleks @ USA.net wrote:

  Great answer... One question though, how would you convert it back to
 X,xxx.00 format??

 number_format($variable,2);


---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread CPT John W. Holmes
From: Dillon, John [EMAIL PROTECTED]

 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?

If you know it's going to be in a $x,xxx.xx format, then

$new_number = preg_replace('/[^0-9.]/','',$old_number);

will remove anything that's not a number or decimal point.

BUT, since we know that we can't trust it'll come in that format, you may
also want to run

$rs = preg_match('/[0-9]+\.?([0-9]{1,2})?/',$new_number); //untested :)

which _should_ make sure you're not getting a number like xxx.xx.xxx or
xx.xx from some tricky user. If $rs is TRUE or 1, then the number is
in the correct format.

---John Holmes...

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]
 could you cast as a float/double before inserting?  $number = (double)
 $string;

 don't know what would happen to the comma, but i assume it would just get
 removed??

Everything after and including the first non-number character would be
dropped.

So $12,000.34 would end up as zero. 12,445 would end up as 12, etc...

---John Holmes...

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread CPT John W. Holmes
From: Peter Beckman [EMAIL PROTECTED]
 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.9. 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



Re: [PHP-DB] number_format problem

2003-11-05 Thread jeffrey_n_Dyke

sweet.  thanks for hte correction.  i try, sometimes i fail. :)




   
 
  CPT John W. 
 
  Holmes  To:   Dillon, John [EMAIL 
PROTECTED], [EMAIL PROTECTED]  
  [EMAIL PROTECTED]cc:   [EMAIL PROTECTED]  
   
  rter.netSubject:  Re: [PHP-DB] number_format 
problem 
   
 
  11/05/2003 11:56 
 
  AM   
 
  Please respond to
 
  CPT John W. 
 
  Holmes  
 
   
 
   
 




From: [EMAIL PROTECTED]
 could you cast as a float/double before inserting?  $number = (double)
 $string;

 don't know what would happen to the comma, but i assume it would just get
 removed??

Everything after and including the first non-number character would be
dropped.

So $12,000.34 would end up as zero. 12,445 would end up as 12, etc...

---John Holmes...

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



Re: [PHP-DB] number_format problem

2003-11-05 Thread CPT John W. Holmes
From: [EMAIL PROTECTED]
 sweet.  thanks for hte correction.  i try, sometimes i fail. :)

But trying is half the battle. GI JOE!

---John Holmes...

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