Velocity Reviews > How to: Convert DOUBLE to PERCENT?

# 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,

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,

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%");

Juan T. Llibre
Guest
Posts: n/a

 07-12-2005
1.
Use custom number formatting :

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,

=?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,

>
>
>