comma in my input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitation
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2005 8:18 am

comma in my input

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: comma in my input

Post 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.
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: comma in my input

Post 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.
nitation
Forum Newbie
Posts: 10
Joined: Sat Aug 20, 2005 8:18 am

Re: comma in my input

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: comma in my input

Post by Eran »

I think money_format is what you are looking for - http://www.php.net/manual/en/function.money-format.php
Post Reply