Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何解析挪威货币_C#_.net_Parsing - Fatal编程技术网

C# 如何解析挪威货币

C# 如何解析挪威货币,c#,.net,parsing,C#,.net,Parsing,如何将挪威货币(kr)解析为十进制 我试图分析这些: 477,60 2.320,00 这段代码不起作用,并抛出一个十进制解析异常,即使我已将挪威指定为解析的区域性 Convert.ToDecimal("2.320,00", System.Globalization.CultureInfo.GetCultureInfo("nb-NO")) 因此,挪威文化没有defineNumberFormat.NumberGroupSeparator,因此您会收到此异常

如何将挪威货币(kr)解析为十进制

我试图分析这些:

477,60
2.320,00
这段代码不起作用,并抛出一个十进制解析异常,即使我已将挪威指定为解析的区域性

Convert.ToDecimal("2.320,00", System.Globalization.CultureInfo.GetCultureInfo("nb-NO"))

因此,挪威文化没有define
NumberFormat.NumberGroupSeparator
,因此您会收到此异常。因此,您需要定义它们:

CultureInfo info = CultureInfo.CreateSpecificCulture("nb-NO");
var numberFormat = info.NumberFormat;
numberFormat.NumberGroupSeparator = ".";
numberFormat.CurrencyGroupSeparator = ".";//this if you are using currency
numberFormat.PercentGroupSeparator = ".";//this for percentages
然后尝试使用
decimal.TryParse
方法:

decimal result = 0;
decimal.TryParse("2.320,00", NumberStyles.AllowDecimalPoint|NumberStyles.AllowThousands, info, out result);

此处

因此挪威文化不具有define
NumberFormat.NumberGroupSeparator
,因此您会收到此异常。因此,您需要定义它们:

CultureInfo info = CultureInfo.CreateSpecificCulture("nb-NO");
var numberFormat = info.NumberFormat;
numberFormat.NumberGroupSeparator = ".";
numberFormat.CurrencyGroupSeparator = ".";//this if you are using currency
numberFormat.PercentGroupSeparator = ".";//this for percentages
然后尝试使用
decimal.TryParse
方法:

decimal result = 0;
decimal.TryParse("2.320,00", NumberStyles.AllowDecimalPoint|NumberStyles.AllowThousands, info, out result);

此处

挪威语是“nb NO”或“nn NO”,如果您使用“nn NO”是否有效?@PeteStensønes NO这对其他文化也不起作用,两者都没有定义NumberGroupSeparator。请确认:这真的是挪威货币格式化的方式吗?glibc中的千位分隔符是一个不间断的空间,许多网站(比如美国)都支持这一点,但我不能肯定自己不是挪威人。这很重要,因为它影响到你应该如何解决问题。如果这实际上是一种自定义格式,那么解析时的自定义代码是有意义的。如果这在挪威的某些地方是标准的,那么修改区域性信息并在整个应用程序中使用它是有意义的。挪威语是“nb NO”或“nn NO”,如果使用“nn NO”,这是否有效?@PeteStensønes NO它也不会与其他区域性一起工作,他们两个都没有定义NumberGroupSeparator。只是想确定一下:这真的是挪威货币格式化的方式吗?glibc中的千位分隔符是一个不间断的空间,许多网站(比如美国)都支持这一点,但我不能肯定自己不是挪威人。这很重要,因为它影响到你应该如何解决问题。如果这实际上是一种自定义格式,那么解析时的自定义代码是有意义的。如果这是挪威某些地区的标准,那么修改区域性信息并在整个应用程序中使用它是有意义的。