C#.NET将字符串转换为十进制谜! [英] C# .NET Convert String to Decimal Mystery!
问题描述
我现在面临有关从字符串转换使用C#.NET为十进制的一个问题。现在的问题是,我已经写了下面的code和我的开发Windows 7的.NET Framework 3.5的系统工作正常。但是,如果我移动应用程序在Windows 2003 Server的.NET 3.5框架的结果是不同的。任何人都可以明白发生什么呢?
I'm facing a problem about the conversion from string to decimal using C# .NET. The problem is that I have wrote the following code and works fine on my development Windows 7 .NET Framework 3.5 system. But, if I move the application on the Windows 2003 Server .NET 3.5 Framework the result is different. Can anyone understand what happen there?
code: DEC = Convert.ToDecimal(strDec);
Code: dec = Convert.ToDecimal(strDec);
Windows 7的结果是:85.00 Windows 2003中的结果:8500
Windows 7 result: 85.00 Windows 2003 result: 8500
感谢你在前进!
推荐答案
这可能是服务器上的区域和文化设置设置为,
为十进制,和。
作为数字分组。请参阅控制面板/地区和区域性设置。
It may be that the region and culture settings on your server are set with ,
as decimal, and .
as digit grouping. See Control Panel/region and culture settings.
如果是由你的应用程序生成该数字串,我会用 CultureInfo.InvariantCulture
在这两个地方。
If this numeric string is generated by your application, I would use CultureInfo.InvariantCulture
in both places.
Decimal dec = 85.0m;
string s = dec.ToString (CultureInfo.InvariantCulture);
decimal.Parse(s, CultureInfo.InvariantCulture);
这篇关于C#.NET将字符串转换为十进制谜!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!