简体   繁体   English

输入的字符串格式不正确

[英]Input string was not in a correct format

I want to store result of total & tempDiscRs into b1..while storing it throws the error that Input string was not in correct format 我想将total&tempDiscRs的结果存储到b1 ..中,同时存储它会引发输入字符串格式不正确的错误

decimal b1 = Convert.ToDecimal(lblDisRate.Text);
b1 = total * tempDiscRs;

You should be aware of the culture you're in. 您应该了解自己所处的文化。

Example: In US, the comma separator is a dot (.) while in Germany it is a comma (,). 示例:在美国,逗号分隔符是点(。),而在德国,则是逗号(,)。

Try 尝试

lblDisRate.Text.ToString(System.Globalization.CultureInfo.InvariantCulture)

In order to use Invariant Culture so you always use a dot instead of a comma. 为了使用不变文化,因此您始终使用点而不是逗号。

decimal myValue;
if(Decimal.TryParse(lblDisRate.Text, out myValue))
{
   //correct
}
else
{
   //wrong
}

See more about Decimal.TryParse Method 查看有关Decimal.TryParse方法的更多信息

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

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