# How to: Convert DOUBLE to PERCENT?

Discussion in 'ASP .Net' started by =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Jul 12, 2005.

1. ### =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=Guest

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=?=, Jul 12, 2005

2. ### Kevin SpencerGuest

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" <> wrote in message
news:...
> 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, Jul 12, 2005

3. ### Mark RaeGuest

"charliewest" <> wrote in message
news:...

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

Mark Rae, Jul 12, 2005
4. ### Juan T. LlibreGuest

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/d...rformatinfoclassnumbergroupseparatortopic.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" <> wrote in message
news:...
> 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,

Juan T. Llibre, Jul 12, 2005
5. ### =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=Guest

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" <> wrote in message
> news:...
> > 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=?=, Jul 12, 2005