[英]I keep getting error {“Input string was not in a correct format.”}
I checked in Visual studio with debug both amtBidded and ItemPrice have values of "xx.xx" with quotation marks around them as if they are strings I would like to convert to a decimal or float. 我在Visual Studio中通过调试检查了amtBidded和ItemPrice的值都为“ xx.xx”,并在其两边加上了引号,就好像它们是要转换为小数或浮点数的字符串一样。 The Parse keeps giving me "Input string was not in a correct format." 解析不断给我“输入字符串的格式不正确”。 error. 错误。 I tried the "culture" solutions that were recommended and still get an error. 我尝试了推荐的“文化”解决方案,但仍然出现错误。
I am at a loss, any help would be appreciated. 我很茫然,任何帮助将不胜感激。
protected void ButtonClicktoBid_Click(object sender, EventArgs e)
{
String CurrentBidder = Context.User.Identity.GetUserName();
String ItemId = ListBoxitemNum.SelectedItem.ToString();
String ItemPrice = ListBoxCurrentPrice.SelectedItem.ToString();
String amtBidded = TextBoxAmtBidded.Text.ToString();
String SecondPlaceBidder =
ListBoxCurrentWinningBidder.SelectedItem.ToString();
String dbMagic;
if (float.Parse(amtBidded) < float.Parse(ItemPrice))
{
Response.Redirect("Default.aspx");
}
Try like this; 这样尝试;
var currentCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
currentCulture.NumberFormat.CurrencyDecimalSeparator = ".";
if (float.Parse(amtBidded, NumberStyles.Any, currentCulture) < float.Parse(ItemPrice, NumberStyles.Any, currentCulture))
{
Response.Redirect("Default.aspx");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.