Page 1 of 1
MySQL Datatype Question
Posted: Thu Jul 06, 2006 9:36 am
by Bigun
I would like to store a number in a field that will have two decimal places at most. I'm currently using a varchar datatype, but it sees 9 higher than 10 because of the whole alphanumeric sort order. What datatype should I use?
Posted: Thu Jul 06, 2006 9:52 am
by Oren
Try TINYINT.
Posted: Thu Jul 06, 2006 9:55 am
by Bigun
It's not saving the decimal points...
saves as
Posted: Thu Jul 06, 2006 9:56 am
by JayBird
As it is a float number, you want o be looking at float, double or decimal datatypes
Posted: Thu Jul 06, 2006 9:58 am
by Bigun
The highest the number will be going is 10, and it will not be going below zero. Which is the most conservative?
Posted: Thu Jul 06, 2006 10:00 am
by JayBird
probably FLOAT(2, 2)
Posted: Thu Jul 06, 2006 10:01 am
by Oren
Bigun wrote:It's not saving the decimal points...
saves as
Sorry... I read too fast and somehow thought you wanted numbers like 0 - 99. Sorry for that

Re: MySQL Datatype Question
Posted: Fri Jul 07, 2006 3:42 am
by AKA Panama Jack
Bigun wrote:I would like to store a number in a field that will have two decimal places at most. I'm currently using a varchar datatype, but it sees 9 higher than 10 because of the whole alphanumeric sort order. What datatype should I use?
Use the DECIMAL datatype. You can specify the number of places on both sides of the decimal point. Plus the DECIMAL datatype doesn have the FAILINGS of the FLOAT datatype when dealing with decimal places.
If the highest number is 10 then set the DECIMAL datatype length to 4,2. This means there are 4 positions and 2 of the positions are right of the decimal point. IE: 00.00
If you set it to 2,2 thinking that means 2 positions to the right and 2 to the left of the decimal point then trying to store a value of 10 will actually store 0.99. This is because the length for the DECIMAL datatype is "total number of positions, how many of the total to the right of the decimal point".