简体   繁体   English

mscorlib.dll中发生了'System.FormatException'类型的未处理的异常其他信息:输入字符串的格式不正确

[英]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.

相关问题 mscorlib.dll中发生类型为'System.FormatException'的第一次机会异常附加信息:输入字符串的格式不正确 - A first chance exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format mscorlib.dll中发生了'System.FormatException'类型的未处理异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll mscorlib.dll中发生了未处理的“System.FormatException”类型异常 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll “ mscorlib.dll中发生了'System.FormatException'类型的未处理的异常” - “An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll” 尝试解析DateTime时-mscorlib.dll中发生了'System.FormatException'类型的未处理异常 - When trying to parse DateTime - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 在C#中将十进制转换为十六进制,并出现错误“ mscorlib.dll中发生了'System.FormatException'类型的未处理异常” - decimal to hexadecimal in c# with mistake “An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll” mscorlib.dll中发生“ System.FormatException”类型的未处理异常,被卡住 - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll, stuck mscorlib.dll 中发生了类型为“System.FormatException”的未处理异常 谁能帮我解决这个错误? - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Can anyone help me with this error? c# 中的运行时错误 - mscorlib.dll 中发生类型为“System.FormatException”的未处理异常 - Run-time error in c# - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 类型为“ System.FormatException”的未处理的异常输入字符串的格式不正确 - Unhandled exception of type “System.FormatException” Input string was not in correct format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM