473,793 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to: Convert DOUBLE to PERCENT?

Hello -

I am reading up on the NumberFormatInf o class, trying to figure out how to
convert a double to a percentage, using the IFormatProvider . This seems a
little beyond me. Can anyone suggest an easy way to convert a double to a
percentage in C#?

For example, i would like to render on my web page the following:
..89 = 89%
1 = 100%

Thanks,
Nov 19 '05 #1
4 9287
Offhand, I'd guess that multiplying the double by 100 would give you the
percent value.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
Hello -

I am reading up on the NumberFormatInf o class, trying to figure out how to
convert a double to a percentage, using the IFormatProvider . This seems a
little beyond me. Can anyone suggest an easy way to convert a double to a
percentage in C#?

For example, i would like to render on my web page the following:
.89 = 89%
1 = 100%

Thanks,

Nov 19 '05 #2
"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
For example, i would like to render on my web page the following:
.89 = 89%
1 = 100%


double dblTest = 0.89;
string strTest = dblTest.ToStrin g("0%");
Nov 19 '05 #3
1.
Use custom number formatting :
Pass your double to {0:0%}

2.
Format the double with the PercentDecimalD igits property.

Double myInt = 0.1234;
Console.WriteLi ne( myInt.ToString( "P", nfi ) );

will return 12.34 %

See samples at :
http://msdn.microsoft.com/library/de...ratortopic.asp

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
=============== =======

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
Hello -

I am reading up on the NumberFormatInf o class, trying to figure out how to
convert a double to a percentage, using the IFormatProvider . This seems a
little beyond me. Can anyone suggest an easy way to convert a double to a
percentage in C#?

For example, i would like to render on my web page the following:
.89 = 89%
1 = 100%

Thanks,


Nov 19 '05 #4
Thanks Kevin,

What i am trying to learn, however, is how to do this using the
NumberFormatInf o class, and/or IFormatProvider interface. This documentation
unfortunately, is not for newbies. Any examples, would be appreciated.

Thanks again,
"Kevin Spencer" wrote:
Offhand, I'd guess that multiplying the double by 100 would give you the
percent value.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
Hello -

I am reading up on the NumberFormatInf o class, trying to figure out how to
convert a double to a percentage, using the IFormatProvider . This seems a
little beyond me. Can anyone suggest an easy way to convert a double to a
percentage in C#?

For example, i would like to render on my web page the following:
.89 = 89%
1 = 100%

Thanks,


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
9893
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double (*func)(double,double)) { nfunc = func ; return qgaus(f1,x1,x2);//error there
17
4379
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
3
2259
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_CalculAXplusB(short int *IN_Tab_entree ,int IN_taille , double *OUT_Tab_sortie_freq , double *OUT_Tab_sortie, double IN_A,
3
7715
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be converted to System.Data.SqlTypes.SqlMoney " How do I get creditlimit into creditlimitS? There seems to be no conversion function. TIA
1
8933
by: Mike9900 | last post by:
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
39
3090
by: VidTheKid | last post by:
THE PROBLEM The % symbol is too vague when defining dimensions in CSS and HTML. It can relate to an inherited value, a measure of the containing element (which can differ between box models) or for background image placement, the size of the element minus the size of the image. A SOLUTION There should be new %-like units defined in CSS to specify what the measurement is a percentage of. These take the form of the % sign and one or...
4
4524
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
116
36002
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused problems elsewhere in another part of the system where that figure was used for some calculation and some eventual truncation led to the system going haywire. So my question is, given this code: int main() { float f = 59.89F;
0
1202
by: gnobbster | last post by:
Hi everyone, I was wondering if it was possible to convert a string value containing numeric characters and a '%' character to a double without doing a character-by-character check manually. For example, "89%" to .89 --- any suggestions?
0
9671
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
9518
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
10212
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...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
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...
0
5436
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...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
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
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.