I have this question, what kind of field do I use for weight as 0.900, 1.200, 2.000, 0.100 and can I treat the fields as number in the query output?
I have this question, what kind of field do I use for weight as 0.900, 1.200, 2.000, 0.100 and can I treat the fields as number in the query output?
I believe that being in grams does not say much, as there is no type of field for each type of measure: grass, kilo, meter, kilometer, etc. < em>
You can use the type decimal , which is recommended for values involving decimals:
-------------↓ 3 decimais
↓ ---
decimal(4,3) // ex. 0.900
↑ -----
--------------↑ 4 dígitos no total, sendo 1 inteiro
The question does not have enough information to nail a type. In addition, it states that it has to record in a certain way, but it does not say why. I see in many situations the person thinks that it has to be that way more could be of another way. The question does not tell if 0.900 is 900 grams or 900 milligrams.
I would record as an integer, that is, record with the smallest possible unit, probably milligrams, so it does not depend on the decimal part. And it would deal with application about this. But nothing prevents the use of a decimal type, and this type should probably be DECIMAL
. The FLOAT
or DOUBLE
might be adequate if the problem allows for inaccuracy, I I prefer to work with exact numbers .
Just like you should not use a numeric type for descriptive data just because they only accept digits , not should use a text type for quantitative data.