471,330 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Parsing percentage % to double

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?
--
Mike
Nov 28 '05 #1
1 8294
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

"Mike9900" <Mi******@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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?
--
Mike

Nov 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

26 posts views Thread by SL33PY | last post: by
1 post views Thread by (PeteCresswell) | last post: by
1 post views Thread by Martin Pöpping | last post: by
4 posts views Thread by marc.omorain | last post: by
7 posts views Thread by Bill Cunningham | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.