访问“测量系统” C# 中的单位名称(kg/lb、m/in 等)

发布于 2024-08-09 14:46:29 字数 308 浏览 1 评论 0原文

Windows 允许将测量系统 配置为公制US 有没有办法使用此设置来读取C# 中的(缩写)单位名称?

例如,当以公制显示重量时,我想显示kg,但在US中我想显示lb。对于长度、体积等也是如此。

我查看了 SystemInformation、CultureInfo、Configuration 和 Globalization,但没有看到任何明显的东西。我错过了什么或者我找错地方了吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩耳倾听 2024-08-16 14:46:29

我相信你能做的最好的事情就是确定你的文化是否是公制的,然后自己处理。我不认为有任何内置格式?我可能是错的,但我在任何地方都找不到任何参考。

这将使您能够确定您的文化是否是公制的:

    CultureInfo culture = new CultureInfo("en-GB");
    RegionInfo regionInfo = new RegionInfo(culture.LCID);
    bool isMetric = regionInfo.IsMetric;

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;
诗化ㄋ丶相逢 2024-08-16 14:46:29

@GenericTypeTea 关于 RegionInfo 是查看位置的说法是正确的。

此外,F# 还包含许多用于处理测量单位的功能。在 F# 中构建一些您需要的内容并从 C# 调用它可能是有意义的。

请参阅 此博文以及后续博文,了解有关 F# 和测量单位的信息。

@GenericTypeTea is right about the RegionInfo being the place to look.

Additionally F# contains a lot of features for working with units of measure. It might make sense to build some of what you need in F# and call it from C#.

See this blog post and the subsequent posts for information about F# and units of measure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文