Decimal fields for currency
Posted: Sat Feb 18, 2012 12:27 pm
Hi guys,
I need to know what's the best way to insert and display currency values in database.
I have a table like this:
id int unsigned auto_increment primary key,
name varchar(30)not null,
category varchar(30)not null,
boughtfor decimal(8,2),
boughtqty int(30),
total decimal(8,2),
saletax decimal(8,2),
date datetime);
The problem being that if a user enters a value like " 10.000", it will insert "10.00".
on the other hand If I change the decimal fields to "decimal(9,3)" if the user enters "10.35" it will insert something like "10.350".
I understand that I can use some php function with a condition to display the values right.
But still, my database values will be all messed up!
Any light shed will be greatly appreciated.
Thanks,
Mike
I need to know what's the best way to insert and display currency values in database.
I have a table like this:
id int unsigned auto_increment primary key,
name varchar(30)not null,
category varchar(30)not null,
boughtfor decimal(8,2),
boughtqty int(30),
total decimal(8,2),
saletax decimal(8,2),
date datetime);
The problem being that if a user enters a value like " 10.000", it will insert "10.00".
on the other hand If I change the decimal fields to "decimal(9,3)" if the user enters "10.35" it will insert something like "10.350".
I understand that I can use some php function with a condition to display the values right.
But still, my database values will be all messed up!
Any light shed will be greatly appreciated.
Thanks,
Mike