则转换为DOUBLE [英] Convert To Double

查看:123
本文介绍了则转换为DOUBLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧IM坐在这个问题挺傻,但我不知道怎么谷歌本作的解决方案。



可以说我有里面值的数据库如1000.00



我把它转换使用双倍 Convert.ToDouble();



不过在我的电脑它的作品,我的服务器上不会,除非我改变字符串和替换



1000,00作品中的服务器上,但是并不1000.00



但是,如果我这样做转换1000,00为Double我不能再在数据库中没有考虑回字符串保存和替换,以



如何能我克服这个问题。
的操作系统是win7的,服务器是SQL Server 2012的

  DataTable的DT = SQLServer.ExecuteQueryWithResults(EXEC CalculateMonthlyBallance) ; 
的foreach(DataRow的行中DT.Rows)
{
ClientCompany CC = Data.Companies.First(C => C.CompanyID ==行[0]的ToString());
财经Saldo =新金融(CC.CompanyID,每月Saldo,每月Saldo,0,0,新的DateTime(DateTime.Now.Year,DateTime.Now.Month,1),F_Type.Saldo, -1);
双RV =行[3] .ToDouble();
MessageBox.Show(本公司ID:+ CC.CompanyID.ToString()++ rv.ToString());
如果(RV,0)
{
Saldo.Debit = RV;
}
,否则如果(行[3] .ToDouble()℃,)
{
Saldo.Credit = -rv;
}

MessageBox.Show(Saldo.Debit ++ Saldo.Credit);
CC.Finances = RetrieveFinances(CC.CompanyID).ToList();
如果(CC.Finances.Count(S =>(S.F_Type == F_Type.Saldo)及及(S.Date ==新日期时间(DateTime.Now.Year,DateTime.Now.Month ,1)))== 0)
{
CC.Finances.Add(Saldo);
CaptureFinancial(Saldo);
}
}


解决方案

的区域设置,具体支配什么符号作为小数点的区域设置,都影响着转换。为了避免这种情况,您需要执行文化不变的转换,使您的计算机上的区域设置不发挥作用。例如:

 双值= double.Parse(stringValue的,CultureInfo.InvariantCulture); 

这是说,我不知道为什么你存储浮点值作为摆在首位的字符串。这是最好的用户输入转换成其自然形态尽早时刻,只有转换回字符串尽可能晚。


Ok im sitting with this issue kind of stupid but I don't know how to google this for the solution.

Lets say i have a database with values inside e.g 1000.00 .

I convert it to double using Convert.ToDouble();

On my PC it works, however on my server it doesn't unless I change to string and replace . with , .

i.e 1000,00 works on the Server but not 1000.00

But if I do Convert 1000,00 to Double I cannot save it again in the database without taking it back to string and replace , with .

How can I overcome this problem. OS is win7, server is SQL Server 2012.

DataTable DT = SQLServer.ExecuteQueryWithResults("EXEC CalculateMonthlyBallance");
            foreach (DataRow row in DT.Rows)
            {
                ClientCompany CC = Data.Companies.First(C => C.CompanyID == row[0].ToString());
                Finance Saldo = new Finance(CC.CompanyID, "Monthly Saldo", "Monthly Saldo", 0, 0, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), F_Type.Saldo, -1);
                double rv = row[3].ToDouble();
                MessageBox.Show("Company ID : " + CC.CompanyID.ToString() + " " + rv.ToString());
                if (rv > 0)
                {
                    Saldo.Debit = rv;
                }
                else if (row[3].ToDouble() < 0)
                {
                    Saldo.Credit = -rv;
                }

                MessageBox.Show(Saldo.Debit + " " + Saldo.Credit);
                CC.Finances = RetrieveFinances(CC.CompanyID).ToList();
                if (CC.Finances.Count(S => (S.F_Type == F_Type.Saldo) && (S.Date == new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1))) == 0)
                {
                    CC.Finances.Add(Saldo);
                    CaptureFinancial(Saldo);
                }
            }

解决方案

The locale setting, specifically the regional settings that govern what symbol is used as a decimal point, are influencing the conversion. To avoid that, you need to perform a culture invariant conversion so that the locale setting on your machine does not play a part. For example:

double value = double.Parse(stringValue, CultureInfo.InvariantCulture);

That said, I do wonder why you are storing floating point values as strings in the first place. It's best to convert user input into its natural form at the earliest possible moment, and only convert back to string as late as possible.

这篇关于则转换为DOUBLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆