jblzg的技术园

关注基于.Net的Web解决方案,高性能数据库设计,高性能Web服务解决方案,关注移动开发

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
今天被一个简单的问题难住了,先上代码:

Convert.ToDecimal("23.34");

各位猜结果是什么?应该是23.34,但实际我的结果是:2334。

后来输出了CurrentCulture看了一下:竟然是:ca-ES;

再后来在此类的构造函数加了如下代码:

Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CN");

问题解决。

问题是:

为什么CurrentCulture会是ca-ES?我操作系统是英文版2003,系统的区域设置是中国。

谢谢 eaglet 同志的提醒,做了个实验:

  • 我将 Regional and Language options > Standards and formats(以下简称RAL_SAF) 修改为 English(United States)
  • 任何一个 Windows Console(以下简称Consolse)输出的 CurrentCulture 都为 en-US,与 RAL_SAF 中的配置一致
  • 任何一个 Windows Service(以下简称Service)输出的 CurrentCulture 都仍为 ca-ES
  • 再后来,我试着修改 Regional and Language options > Advanced > Default user account settings 为选中,确定后,再次运行 Service,输出就变成了 en-US
  • 再将 RAL_SAF 改回 Chinese(PRC),运行Service,CurrentCulture 结果仍然是 en-US
  • 再将 Regional and Language options > Advanced > Default user account settings 取消选中、再选中,运行 Service,结果为 zh-CN

得出结论:

  1. Windows Console 的 CurrentCulture 随着 Regional and Language options > Standards and formats 的改变而实时改变;
  2. Windows Service 在未将 Regional and Language options > Advanced > Default user account settings 选中时,CurrentCulture值有可能与 Regional and Language options > Standards and formats 的配置不同
  3. 为了每次修改 Regional and Language options > Standards and formats实时生效,需要将Regional and Language options > Advanced > Default user account settings重新选中并确定

忽然想起来自己的系统第一次安装时,可能因为鼠标滚轮的问题,本来 RAL_SAF 要选择 Chinese(PRC),结果误选为 Catalan(加泰罗尼亚),所以又做了一个测试:将 RAL_SAF 改为 Catalan,Regional and Language options > Advanced > Default user account settings 重新选中并确定,运行Service,输出结果为 ca-ES。

至此,该问题的原因、解决方案都有了。

posted on 2009-01-07 16:39  jblzg  阅读(1246)  评论(1编辑  收藏  举报