Page 1 of 1

comma in my input

Posted: Wed Jun 25, 2008 6:40 pm
by nitation
Hello,

I am trying to calculate in php. But my problem is, i want a figure like this ( $25,000.20) in MYSQL database, but none of my column types are accepting it.

I tried Float, Double, Decimal, but none is working. They only allow my script to calculate the numbers before the (,) comma sign. Is there something am not doing right???
This is what am calculating;

Code: Select all

 
<?php
 
if($amount - $amount_to_send < 100) {
$msg='Error, The amount you specified is higher than your transfer limit';
}
?>
 
Thanks in advance.

Re: comma in my input

Posted: Wed Jun 25, 2008 7:04 pm
by Eran
The comma is just formatting, not a part of the number. If you insist on having it in the database, you can't use any of the number type fields - you have to use a text field instead (VARCHAR/CHAR or TEXT/BLOB).

I suggest leave formatting to PHP and leave the comma out.

Re: comma in my input

Posted: Wed Jun 25, 2008 8:48 pm
by WebbieDave
pytrin wrote:I suggest leave formatting to PHP and leave the comma out.
Agreed. Make it a float in the database and format it in PHP with the aptly named number_format function.

Re: comma in my input

Posted: Thu Jun 26, 2008 2:28 am
by nitation
I have visited php.net for the number_formats but it doesn't seem understanding to me. I still can't figure out how to format the numbers to meet my needs.

Re: comma in my input

Posted: Thu Jun 26, 2008 3:34 am
by Eran
I think money_format is what you are looking for - http://www.php.net/manual/en/function.money-format.php