only calculate before the comma

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

only calculate before the comma

Post by nitation »

Hello people,

I am having problems with the comma sign in the amount field. I have a figure in my amount field that looks like this;

7500004

when i try to transfer a sum that looks like 750,0004, it will only calculate all the figures before the comma.

I wanna know if i have an error in my database or what.

my table looks like this

amount varchar(255);

do i need to change the column type to something like FLOAT, DECIMAL or what.

Thanks in advance
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: only calculate before the comma

Post by califdon »

nitation wrote:Hello people,

I am having problems with the comma sign in the amount field. I have a figure in my amount field that looks like this;

7500004

when i try to transfer a sum that looks like 750,0004, it will only calculate all the figures before the comma.

I wanna know if i have an error in my database or what.

my table looks like this

amount varchar(255);

do i need to change the column type to something like FLOAT, DECIMAL or what.

Thanks in advance
There's no problem with your database. All databases that I know of store numbers without commas as "thousands" markers. That's totally a U.S. practice, anyway. Since databases are used around the world, the way they store data must be compatible with other languages and practices. There are ways to display large numbers with commas, but they are never stored that way, so you must never input them that way. You can use the preg_replace() function to remove any commas before writing to a record in the database.
Post Reply