带小数点分隔符的本地化

发布于 2024-07-15 05:09:14 字数 254 浏览 5 评论 0原文

.NET 是否有可能在服务器 A 上使用“,”作为小数分隔符,而在另一个服务器 B 上使用“.”? + 你如何检测到这一点?

将字符串转换为双精度数时,在服务器 A 上一切正常,但在服务器 B 上我们遇到问题。

示例:

服务器 A:20,4 --> 20.4 服务器B:20,4 --> 204

我们需要检测到这一点,以便两台服务器上的东西都能继续工作。

谢谢,利文·卡登

Is it possible that .NET uses on server A ',' as decimal separator and on another server B '.'? + How can you detect this?

When converting strings to doubles, on server A everything works fine, but on server B we have problems.

Example:

server A : 20,4 --> 20.4
server B : 20,4 --> 204

We would need to detect this so that on both servers things keep on working.

thx, Lieven Cardoen

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

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

发布评论

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

评论(2

紫轩蝶泪 2024-07-22 05:09:14

听起来好像在一台服务器上正确设置了区域设置,但在另一台服务器上则不然。

有几种方法可以做到这一点,但您可能希望使用 Thread.CurrentThread.CurrentCulture 和 Thread.CurrentThread.CurrentUICulture 在 App/ASP.NET 页面中设置当前线程的区域设置。

要为整个应用程序进行此设置,您可以在 web.config 中执行以下操作:

<configuration>
  <system.web>
    <globalization culture="en-US" uiCulture="en-US" />
...

Sounds like the locale is being set correctly on one server but not the other.

There are a few ways you could do this, but you might want to set the locale for the current thread in your App/ASP.NET page using Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture.

To set this for the entire application, you'd do this in your web.config:

<configuration>
  <system.web>
    <globalization culture="en-US" uiCulture="en-US" />
...
弃爱 2024-07-22 05:09:14

使用

String.Format(System.Globalization.CultureInfo.InvariantCulture, ....)

我在您不希望有特定于文化的输出的情况下 。 (例如,当您为其他应用程序编写序列化数据等时)这样,无论当前设置什么文化,输出都将始终相同。

I use

String.Format(System.Globalization.CultureInfo.InvariantCulture, ....)

in those cases where you do not want to have culture specific output. (For example, when you write serialize data for other applications etc.) This way no matter what Culture is currently set, the output will always be the same.

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