convert string number to integer [duplicate]
Possible Duplicate:
Convert.ToInt32() a string with Commas
i have a value in the label as: 12,000
a开发者_运维知识库nd i wish to convert it into an integer like 12000 (use it for comparison)
i tried int k = convert.toint32("12,000"); this does not work.
Thanks
You're being screwed up by the comma. If all of your values have commas in them, you'll want to run a string.replace() to remove them. Once that comma is gone, it should work fine.
A more thorough way would be to Parse it, allowing for thousands.
Try the following
var number = Int32.Parse("12,000", System.Globalization.NumberStyles.AllowThousands);
Try this
string num = "12,000"; int k = Convert.ToInt32(num.Replace(",",""));
string k = "12,000";
int i = Convert.ToInt32(k.Replace(",", ""));
will work
精彩评论