How to get the user preferred units? (metric (meters) or imperial (miles))?

Regis_AG picture Regis_AG · Aug 11, 2011 · Viewed 11.9k times · Source

I would like to know what are the user-preferred units between miles and meters. It seems that the "Locale" class doesn't allow that.

Answer

Peter O. picture Peter O. · Aug 11, 2011

Although there isn't a way to get the preferred units using Locale, you can assume by default that if the Locale indicates the United States or Myanmar (locale.getISO3Country().equalsIgnoreCase("usa") || locale.getISO3Country().equalsIgnoreCase("mmr")) the preferred units are imperial, otherwise the preferred units are metric. In any case where units may be shown in either imperial or metric form, the measurement system shown should be a user-settable preference.

There are certain idiosyncrasies involving units in some countries. (See also the accepted answer at the time of this writing.) For example, although the preferred everyday units in the United Kingdom are metric units, there are some exceptions, notably—

  • miles and miles per hour, in ground transportation;
  • miles per hour, in wind speeds;
  • pints and gallons, for milk and beer (but not most other foods and beverages); and
  • stone, or stone and pounds, for a person's weight.