473,698 Members | 2,337 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 8917
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
18531
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
6866
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
1540
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
3699
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
3382
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
1685
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
11938
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
2544
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
3422
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
8676
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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
6522
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
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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.