mardi 10 février 2015

Storing floating point values for various units of measurement (kg, ml, mm, pl) in PostgreSQL


I have a table like the following



order_item
------------
serial | id (PK)
integer | order_id
???? | quantity
integer | unit_of_measure_id (PK) --> ml, l, kg, mg, mm, m, etc.


I'm doing an application where I need to store the amount of material used in chemical analysis. Sometimes the materials are used in such a small amount as microliters, or sometimes more, like one or two liters.


Is it the numeric datatype good enough?


I have read that it is a good idea to convert the values to the smallest unit of measure. So if I have 10 liters, I have to pass to 10000000 microliters. But what if you need to use a unit of measurement even lower in the future? like picoliters? Inevitably, the application will have to use floating point numbers I think.


I hope you understand my question, my English is not very good. Thanks.





Aucun commentaire:

Enregistrer un commentaire