How to: Convert DOUBLE to PERCENT?

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

  1. 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
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    Mark Rae Guest

    "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
    #3
  4. 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/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
    #4
  5. 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
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cGhpbGxpcA==?=

    Regexp and percent signs

    =?Utf-8?B?cGhpbGxpcA==?=, Sep 24, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    636
    =?Utf-8?B?cGhpbGxpcA==?=
    Sep 24, 2004
  2. Dmitri

    Percent JFormattedField

    Dmitri, Nov 22, 2004, in forum: Java
    Replies:
    2
    Views:
    1,930
    Dmitri
    Nov 23, 2004
  3. da Vinci
    Replies:
    5
    Views:
    8,751
    da Vinci
    Jul 31, 2004
  4. Sydex
    Replies:
    12
    Views:
    6,575
    Victor Bazarov
    Feb 17, 2005
  5. Heiko Vogel
    Replies:
    3
    Views:
    577
    Method Man
    Sep 14, 2004
Loading...

Share This Page