[英]A first chance exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format
[英]An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format
//Declaring of "Total Statements"
double NetSalary, PensionFundPercentage, grossSalary, TaxableAmount, MonthlySalary, Allowance, Paye, Uif, MedicalAid, totalDeduction;
double PensionFund;
double Other = 0;
double.TryParse(txtOtherDeductions.Text, out Other);
//Convert Statements
Allowance = Convert.ToDouble(txtDeductions.Text);
PensionFund = Convert.ToDouble(txtPenFund.Text);
Paye = Convert.ToDouble(txtPayasUEarn.Text);
即时消息无法计算薪水来抵消所要求的金额
尝试本地化失败的地方。
取自msdn。
备注
使用ToDouble(String)方法等效于将值传递给Double.Parse(String)方法。 值是使用当前线程区域性的格式约定来解释的。
如果您不想在转换失败的情况下不处理异常,则可以调用Double.TryParse方法。 它返回一个布尔值,该值指示转换是成功还是失败。
在此处阅读更多信息: https : //msdn.microsoft.com/zh-cn/library/zh1hkw6k(v=vs.110).aspx
也许,在调用Convert.ToDouble(...)时尝试使用NumberFormatInfo。 我认为NumberFormat(或缺乏)可能是一个原因。 例如,
txtPenFund.Text = "2.00,00"; // assuming a convenient example to get exception
double PensionFund;
PensionFund = Convert.ToDouble(txtPenFund.Text); // will throw format exception
如果使用NumberFormatInfo,则可以将字符串转换为预期的两倍。
NumberFormatInfo numFormat = new NumberFormatInfo();
numFormat.NumberDecimalSeparator = ",";
numFormat.NumberGroupSeparator = ".";
// somewhere in the UI, txtPenFund is set
txtPenFund.Text = "2.00,00";
double PensionFund;
PensionFund = Convert.ToDouble(txtPenFund.Text, numFormat);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.