5

My app is launching to a US audience first, but I want to internationalize the database schema for future expansion. Obviously I will convert between the two units as necessary regardless, but are there any benefits to storing one or the other in the database? My initial thought is that it might be helpful to store kilometers since miles are used by less countries worldwide, so long-term, I will be doing less conversions overall. But in the short-term, while the app is still US-only, I will be converting units every time I access the database.

Paul White
  • 94,921
  • 30
  • 437
  • 687
Hugh Guiney
  • 151
  • 4

2 Answers2

5

I'd recommend storing everything in Planck Lengths. That way you get the most accuracy possible.

The Planck length, is the unit of length approximately 1.6 * 10^-35 metres. It is in the system of units known as Planck units. The Planck length is deemed "natural" because it can be defined from three fundamental physical constants: the speed of light, Planck's constant, and the gravitational constant. Max Planck was the first to propose the Planck length, a base unit in a system of measurement he called "natural units". Although quantum mechanics and general relativity were unknown when Planck proposed his natural units, it later became clear that at a distance equal to the Planck length, gravity begins to display quantum effects, whose understanding would require a theory of quantum gravity.

Meter lengths are an easy conversion of "x" meters divided by 1.6e+35.

Of course, you going to need a fairly large data type to store your measurements.

All kidding aside, why not store the unit-of-measurement with the actual measurement (in a separate column of course, probably as a foreign key). This way when you are displaying the measurement you do not need to convert it at all. Simply display the measurement, along with the unit of measure. The only time you'll need to convert the measurement is if you want to compare it to other measurements in a different unit.

Hannah Vernon
  • 70,928
  • 22
  • 177
  • 323
3

I would go with m unit and int datatype, as meters are SI unit and int should be the fastest and the most memory effective.

mvorisek
  • 428
  • 1
  • 5
  • 20