开发者

convert string number to integer [duplicate]

开发者 https://www.devze.com 2023-01-29 18:58 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Convert.ToInt32() a string with Commas
This question already has answers here: Closed 12 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消