Parsing percentage % to double

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
Back
Top