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
> 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
> the database, which is hinted at in the notes on number_format.  I suppose
> 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 "" or
"xx.xxxxxx" from some tricky user. If $rs is TRUE or 1, then the number is
in the correct format.

---John Holmes...

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to