What is the best datatype for holding percent values ranging from 0.00% to 100.00%?
A:
If 2 decimal places is your level of precision, then a "smallint" would handle this in the smallest space (2-bytes). You store the percent multiplied by 100.
EDIT: The decimal type is probably a better match. Then you don't need to manually scale. It takes 5 bytes per value.
mdma
2010-05-04 01:54:01
+2
A:
Assuming two decimal places on your percentages, I would store the data in a decimal(5,3)
data type with a CHECK
constraint that ensures that the values never exceed 1.00 (assuming that is the cap) and never go below 0 (assuming that is the floor). Combined with a good column name, it makes it clear to other developers what the data is and how the data is stored in the column.
Thomas
2010-05-04 02:03:39