简体   繁体   English

相同的文化,不同的价值转换

[英]Same Culture, different value conversions

My website extracts data from a text-file into a database.我的网站从文本文件中提取数据到数据库中。 After reading the data, I convert string-values into double, using:读取数据后,我将字符串值转换为双精度值,使用:

oracom.Parameters.Add("nstpreisvm", OracleDbType.Double).Value = Convert.ToDouble(_material.Mat_StPreisVm);

If I check the results in the database now, (The column expects the NUMBER -format), I get two different values: On my localhost via Visual Studio 2010, the database returns 10,15 - But if I make the process on the webserver, the database only shows 10 .如果我现在检查数据库中的结果(该列需要NUMBER格式),我会得到两个不同的值:在通过 Visual Studio 2010 的本地主机上,数据库返回10,15 - 但是如果我在网络服务器上进行处理, 数据库只显示10 . How does this happen?这是怎么发生的?

I implemented a little lable on the website now, filling it with the current culture on the Page-Load:我现在在网站上实现了一个小标签,在页面加载上用当前的文化填充它:

label.Text = Thread.CurrentThread.CurrentCulture.ToString();

The CurrentCulture is en-GB for both instances, so what is the problem here? CurrentCulture在这两个实例中都是en-GB ,那么这里的问题是什么? Am I missing anything?我错过了什么吗?


My local windows is Win7 SP1 with a german language-pack, the server is Win2008 R2 with standard English installation.我的本地windows是Win7 SP1,带德语语言包,服务器是Win2008 R2,标准英文安装。

We had a similar problem on a customer server where the customer had manually changed the decimal separator symbol for a particular culture on that server.我们在客户服务器上遇到了类似的问题,客户手动更改了该服务器上特定文化的小数点分隔符。 You can check this using:您可以使用以下方法检查:

Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator

I would suggest explicitly specifying the decimal separator symbol when you do the parsing:我建议在解析时明确指定小数点分隔符:

Double.Parse("1,25", new NumberFormatInfo(){ NumberDecimalSeparator = "," });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM