Formatting Numbers for a DropDownList

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Sep 26, 2007.

  1. I am using databinding to populate a dropdownlist with numeric values. Some
    of the values have more decimal places than others, and I only want the
    minimal number of decimal places necessary displayed. The only way I have
    found to do this is to use the following for the DataTextFormatString
    property:

    "{0:0.######}"

    This displays what I want for now, but if the number had more that 6 decimal
    places, it would not work. Is there any way to have the number of decimal
    places determined and displayed automatically? My data is coming from an SQL
    Server 2005 database, and the field in question is declared as numeric(7,5).
    I realize that this field can never have more than 5 decimal places, but I
    would think there would be a more efficient and easier way to say "Only
    display the necessary decimal places". Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Sep 26, 2007
    #1
    1. Advertising

  2. That would return the correct value if I were trying to format a String
    variable, but I am using DataBinding with a DropDownList. Therefore, the
    only means of formatting my text value is to use the DataTextFormatString
    property (Obviously I could just loop through the results returned by the
    database to use your suggestion, but that is more work and probably less
    efficient). The DataTextFormatString uses a FormatString, not String
    methods. Any other ideas? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >
    >> I realize that this field can never have more than 5 decimal places, but
    >> I would think there would be a more efficient and easier way to say "Only
    >> display the necessary decimal places". Thanks.

    >
    > .ToString().TrimEnd('0');
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Nathan Sokalski, Sep 27, 2007
    #2
    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. Onur Bozkurt

    Formatting numbers with asp

    Onur Bozkurt, Aug 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    471
    Grant
    Aug 4, 2003
  2. Marcelo

    Re: Formatting numbers

    Marcelo, Aug 15, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    386
    Marcelo
    Aug 15, 2003
  3. John Wilson

    formatting numbers & columns in datagrid

    John Wilson, Sep 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    932
    George Durzi
    Sep 2, 2003
  4. =?Utf-8?B?UGx1bmFsZG8=?=

    Formatting Numbers

    =?Utf-8?B?UGx1bmFsZG8=?=, Apr 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    Martin Dechev
    Apr 15, 2004
  5. Nathan Sokalski

    Formatting Numbers for a DropDownList

    Nathan Sokalski, Sep 26, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    581
    Mark Rae [MVP]
    Sep 27, 2007
Loading...

Share This Page