Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to: Convert DOUBLE to PERCENT?

Reply
Thread Tools

How to: Convert DOUBLE to PERCENT?

 
 
=?Utf-8?B?Y2hhcmxpZXdlc3Q=?=
Guest
Posts: n/a
 
      07-12-2005
Hello -

I am reading up on the NumberFormatInfo 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,
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      07-12-2005
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

"charliewest" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello -
>
> I am reading up on the NumberFormatInfo 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,



 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      07-12-2005
"charliewest" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

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


double dblTest = 0.89;
string strTest = dblTest.ToString("0%");


 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      07-12-2005
1.
Use custom number formatting :
Pass your double to {0:0%}

2.
Format the double with the PercentDecimalDigits property.

Double myInt = 0.1234;
Console.WriteLine( 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...
======================

"charliewest" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello -
>
> I am reading up on the NumberFormatInfo 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,




 
Reply With Quote
 
=?Utf-8?B?Y2hhcmxpZXdlc3Q=?=
Guest
Posts: n/a
 
      07-12-2005
Thanks Kevin,

What i am trying to learn, however, is how to do this using the
NumberFormatInfo 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
>
> "charliewest" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello -
> >
> > I am reading up on the NumberFormatInfo 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,

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
from List <double> to double[] Web learner ASP .Net 3 04-26-2006 05:26 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
Double double display display problem problem Tom Accuosti Firefox 3 09-27-2004 10:02 PM
How to convert a double **ptr in a double const ** const ptr? Heiko Vogel C Programming 3 09-14-2004 10:23 AM
Help: Double convert to Integer and Double.... da Vinci C++ 5 07-31-2004 12:35 AM



Advertisments