473,804 Members | 4,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing percentage % to double

I use this code, but I get exception:

String num = "29%";
System.Globaliz ation.NumberFor matInfo ni = new
System.Globaliz ation.NumberFor matInfo(); ni.PercentSymbo l = "%";
double nums = double.Parse(nu m, System.Globaliz ation.NumberSty les.Any, ni);

Is there a way to parse the percent value by using IFormatProvider ?
--
Mike
Nov 28 '05 #1
1 8935
How about:

String num = "29%";
double nums = double.Parse(nu m.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******@discu ssions.microsof t.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
I use this code, but I get exception:

String num = "29%";
System.Globaliz ation.NumberFor matInfo ni = new
System.Globaliz ation.NumberFor matInfo(); ni.PercentSymbo l = "%";
double nums = double.Parse(nu m, System.Globaliz ation.NumberSty les.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
18536
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 = 40% But I wanted to do the reverse of that....to calculate the SellPrice, where only Cost and the desired GPP are supplied. I was struggling with my high-school math, and having a heck of a time with
26
6882
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 is in my Watch:
1
1542
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 equivalent. (e.g. .33456 for 33.456%). What am I doing wrong? -- PeteCresswell
1
3711
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 records = root.ChildNodes;
4
3393
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. My application is unresponsive for this time, so I would like to show a progress bar. I could show a spinner to show that the application is responsive, but I would prefer to show a percentage. Is there any way to query the parser to see how...
0
1691
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) { btnTestCPUPerc.Click += new
3
11948
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 add to it for my next assignment. I dont want to go to my next assignment when I cannot even fix this error. The error and it is the only error I have thank goodness, says "reached end of file while parsing". Can anyone please take a look, thank you...
7
2549
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 percentage lost or gained by the first number using the second number. This program is reporting to me the opposite of what it should and I have tried everything. It says this. 20 2 or 2 from 20 leaving 18 is 90% loss.
4
3425
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 character when logging? I've tried to Google it a while but i saw nobody giving a suggestion for a resolution.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.