如何转换" 12.4"为十进制EN-US文化 [英] How to convert "12,4" to decimal en-Us culture

查看:198
本文介绍了如何转换" 12.4"为十进制EN-US文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我中存储有字符串列在数据库中,在挪威培养十进制值(133,3)。

I have a decimal value ("133,3") stored in string column in the database, in norway culture.

后该用户改变了区域设置到英语(美国)。当我转换133,3为十进制使用CultureInfo.InvariantCulture,越来越无效值或错误。

after that user changed the regional setting to english-Us. when I convert "133,3" to decimal using CultureInfo.InvariantCulture, getting invalid value or error.

有来处理的 C#这种情况下任何最好的方法应用程序?

问候,
阿南德

regards, Anand

推荐答案

不管是制度文化,如果指定 CultureInfo.InvariantCulture 你的不会的能够解析133,3作为十进制到133.3。这同样适用于美国英语如此。

Regardless of the system culture, if you specify CultureInfo.InvariantCulture you won't be able to parse "133,3" as a decimal to 133.3. The same is true for US English.

您的可能的只是解析值(使用的 decimal.TryParse 这需要一个的IFormatProvider ),或(最好)更改数据库中的字段,以反映真实的数据类型(十进制数)来代替。

You could just specify a Norwegian culture when parsing the value (using the overload of decimal.TryParse which takes an IFormatProvider), or (preferrably) change the field in the database to reflect the real data type (a decimal number) instead.

这篇关于如何转换" 12.4"为十进制EN-US文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆