惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
K
Kaspersky official blog
A
Arctic Wolf
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
W
WeLiveSecurity
Know Your Adversary
Know Your Adversary
博客园 - Franky
T
Tenable Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Help Net Security
Help Net Security
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
J
Java Code Geeks
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
O
OpenAI News
The Cloudflare Blog
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
V
V2EX
罗磊的独立博客
美团技术团队
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏

博客园 - jblzg

用powershell脚本实现Andoird为不同市场编译、签名自动化,效率极大提高 JSON与Protocol Buffers Visual Studio 2008提高工作效率的小技巧 转:批处理获得任意天前的日期 SQL Server 2008 事务日志物理文件尺寸无法减小的解决办法(含日志收缩(shrink)技巧) 用虚拟机实际体验Google Chromium OS (Chrome OS) Pre-Built 2009年互联网5大趋势之一:结构化的数据 由一个案例引出SQL注入防范(WebKnight),补救(数据修复)的思考 参加Google Developer Day 2009归来 网站首页、频道首页静态化的问题 宽高比例不固定的用户头像纵向居中的方法(不使用表格、代码精简、图片不变形) Canonical URL Tag - 继SiteMap之后最重要的搜索引擎优化实践 - jblzg 对常规启用 IIS6.0 Gzip 方法的补充,用于解决wget、curl等无法得到压缩结果的问题 FCKeditor.NET的配置、扩展与安全性经验交流 搜狐博客列表页面分析 ASP.NET Web 开发中的静态资源(JS、CSS、图片)版本控制 避免修改Web.config的appSettings配置时导致的所有页面重编译 参加Google Developer Day 2008归来 一次有趣的Debug——使用Lumigent Log Explorer对SQL Server事务日志进行分析,对SQL Server事务、操作进行撤销(恢复)
金额字符串转换成Decimal格式的怪问题引发的思考
jblzg · 2009-01-07 · via 博客园 - jblzg

今天被一个简单的问题难住了,先上代码:

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。

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