Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing "Measurement System" unit names (kg/lb, m/in, etc) in C#

Tags:

c#

regional

Windows allows configuration of Measurement system to Metric or U.S. Is there a way to use this setting to read (abbreviated) unit names in C#?

e.g. when displaying a weight in Metric I want to show kg but in U.S. I want to show lb. Similarly for length, volume, etc.

I've looked at SystemInformation, CultureInfo, Configuration, and Globalization, but didn't see anything obvious. Did I miss something or am I looking in the wrong place?

like image 991
WileCau Avatar asked Oct 27 '09 08:10

WileCau


1 Answers

I believe the best you can do is to determine if your culture is metric or not and then handle it yourself. I don't think there's any built in formatting? I may be wrong though, but I cannot find any reference to it anywhere.

This will allow you to determine if your culture is metric or not:

    CultureInfo culture = new CultureInfo("en-GB");
    RegionInfo regionInfo = new RegionInfo(culture.LCID);
    bool isMetric = regionInfo.IsMetric;
like image 128
djdd87 Avatar answered Oct 05 '22 01:10

djdd87