C#.NET将字符串转换为十进制谜!转换为、字符串、NET、十进制谜

由网友(夏沫の初浅)分享简介:我现在面临有关从字符串转换使用C#.NET为十进制的一个问题。现在的问题是,我已经写了下面的code和我的开发Windows 7的.NET Framework 3.5的系统工作正常。但是,如果我移动应用程序在Windows 2003 Server的.NET 3.5框架的结果是不同的。任何人都可以明白发生什么呢?I'm...

我现在面临有关从字符串转换使用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);
阅读全文

相关推荐

最新文章