Hacker News new | ask | show | jobs
by strogonoff 299 days ago
When recording data, it is best to store it as literally as possible. Your data processing layer can adjust it in whatever way necessary for reporting, and that logic can change, but what should not change is whatever the user has entered, no matter when they look at it again.

Imagine you record length and your user enters 7.4 ft. You store an integer number of millimetres, and the nearest one is 2256. For a while it is fine, but at some point someone on GUI side makes conversion more precise and now from vantage point of the user the original 7.4 ft somehow retroactively became 7.401575 ft.

While a basic string could be the most reliable way to preserve data as entered, numbers with decimal point are formatted differently across countries, so it you want a 1,25 entered in Sweden to appear as 1.25 after your user moves to the US, it makes sense to record it using a decimal structure exactly as entered, along with a unit of measure. Another benefit of decimal structures is that you can store precision and thus distinguish a 7.4 ft that could have been 7.39 ft or 7.41 ft (the measuring device was not very accurate) from exactly 7.400 ft.