Parsing percentage % to double

G

Guest

I use this code, but I get exception:

String num = "29%";
System.Globalization.NumberFormatInfo ni = new
System.Globalization.NumberFormatInfo(); ni.PercentSymbol = "%";
double nums = double.Parse(num, System.Globalization.NumberStyles.Any, ni);

Is there a way to parse the percent value by using IFormatProvider?
 
K

Kevin Spencer

How about:

String num = "29%";
double nums = double.Parse(num.Substring(0, num.IndexOf('%'))) / 100D;

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top