[英]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);
IM UNABLE TO CALCULTE THE SALARY AMOUNT TO AGAINST THE THE AMOUNT QUOTED
即时消息无法计算薪水来抵消所要求的金额
Try localize the where it fails. 尝试本地化失败的地方。
Taken from msdn. 取自msdn。
Remarks 备注
Using the ToDouble(String) method is equivalent to passing value to the Double.Parse(String) method. 使用ToDouble(String)方法等效于将值传递给Double.Parse(String)方法。 value is interpreted by using the formatting conventions of the current thread culture.
值是使用当前线程区域性的格式约定来解释的。
If you prefer not to handle an exception if the conversion fails, you can call the Double.TryParse method instead. 如果您不想在转换失败的情况下不处理异常,则可以调用Double.TryParse方法。 It returns a Boolean value that indicates whether the conversion succeeded or failed.
它返回一个布尔值,该值指示转换是成功还是失败。
Read more here: https://msdn.microsoft.com/en-us/library/zh1hkw6k(v=vs.110).aspx 在此处阅读更多信息: https : //msdn.microsoft.com/zh-cn/library/zh1hkw6k(v=vs.110).aspx
Perhaps, try using NumberFormatInfo while calling Convert.ToDouble(...). 也许,在调用Convert.ToDouble(...)时尝试使用NumberFormatInfo。 I assume NumberFormat (or lack of) it could be a reason.
我认为NumberFormat(或缺乏)可能是一个原因。 For example,
例如,
txtPenFund.Text = "2.00,00"; // assuming a convenient example to get exception
double PensionFund;
PensionFund = Convert.ToDouble(txtPenFund.Text); // will throw format exception
If I use NumberFormatInfo, I can convert the string to double as expected. 如果使用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.