By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

How to: Convert DOUBLE to PERCENT?

P: n/a
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,
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <ch*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
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,

Nov 19 '05 #2

P: n/a
"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.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.ToString("0%");
Nov 19 '05 #3

P: n/a
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" <ch*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
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,


Nov 19 '05 #4

P: n/a
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" <ch*********@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
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,


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.