juF*_*uFo 7 c# parsing decimal
简短的问题:
为什么这些' ..... '在.NET(C#)中解析小数有效:
decimal res = decimal.Parse("8......15"); // returns 815
decimal res = decimal.Parse("8...15"); // returns 815
decimal res = decimal.Parse("8..15"); // returns 815
Run Code Online (Sandbox Code Playgroud)
这是什么原因?
Jon*_*eet 19
它失败了.你是否有机会参加"."文化.千位分隔符和","是小数点?Decimal.Parse
(和类似的调用)默认使用线程的当前文化.这是否是一件好事是有争议的,但与实际行为无关:)
尝试CultureInfo.InvariantCulture
在decimal.Parse
通话中指定:
decimal res = decimal.Parse("8......15", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
我相信这会表现得像你期望的那样.