473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 8787
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Don Leverton | last post by:
Hi Folks, I *can* calculate the Gross Profit Percentage where both the Cost and SellPrice are known, using the formula: (SellPrice - Cost) / SellPrice = GPP eg ($24.92 - $14.95) / $24.92 =...
26
by: SL33PY | last post by:
Hi, I'm having a problem parsing strings (comming from a flat text input file) to doubles. the code: currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "), System.Double) What...
1
by: (PeteCresswell) | last post by:
I am storing a percentage in a Double field. No problem formatting it for presentation (e.g. .33456 shows as 33.456%). But when the user edits the field, they have to type in the decimal...
1
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList...
4
by: marc.omorain | last post by:
Hi there, I have a 28mb XML file which I parse with SAX. I have some processing to do in the startElement / endElement callbacks, which slows the parsing down to about 60 seconds on my machine....
0
by: ipramod | last post by:
Hi, I just wanted to calculate CPU Percentage Utilization in ASP.Net application using a thread. I have written following code: protected void Page_Load(object sender, EventArgs e) {...
3
by: spittinfire | last post by:
-------------------------------------------------------------------------------- I am trying to correct the errors on an assignment that has already been graded because I have to now modify it and...
7
by: Bill Cunningham | last post by:
I need help on this utillity it is supposed to take as its first argument a number and its second argument a subtraction of that number say for example 20 and 2. The program should calculate the...
4
by: K Viltersten | last post by:
It seems that when i try to write a percentage sign (%) into the event log using WriteEntry method, the log believes that i'm refering to some variable from command line. Is it a special...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.