I need to capture user’s height and weight in my database. In the UI, I need to provide an option to specify height in centimeters and inches — and for weight, kilograms and pounds. Later on, when I display the users, I need to display their height and weight in only 1 unit of measurement (e.g. either in cms or ins for all of them).
What’s the best way to store this data? Do I store 2 pieces of data for height (e.g. height value, height unit) and 2 pieces of data for weight (e.g. weight value, weight unit), then store user’s data as inputted? When I need to display the data in uniform units, then I do conversion in the SQL.
Or should I convert the data before being stored that way I don’t need to do conversation later when I need to display the user data?
By the way, when I display the data back to the actual user, it has to be in the same units the user picked.
Think normalization – unless there is a compelling reason to do otherwise, store it in one place, in one format, and always use the standard conversion in your code later on. The database should store your data, not the business rules.