HighTechTalks DotNet Forums  

Formatting Numbers for a DropDownList

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss Formatting Numbers for a DropDownList in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default Formatting Numbers for a DropDownList - 09-26-2007 , 06:19 PM






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
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
Mark Rae [MVP]
 
Posts: n/a

Default Re: Formatting Numbers for a DropDownList - 09-26-2007 , 06:33 PM






"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote


Quote:
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



Reply With Quote
  #3  
Old   
Nathan Sokalski
 
Posts: n/a

Default Re: Formatting Numbers for a DropDownList - 09-27-2007 , 11:33 AM



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
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <mark (AT) markNOSPAMrae (DOT) net> wrote

Quote:
"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote in message
news:uSlQ3sIAIHA.1164 (AT) TK2MSFTNGP02 (DOT) phx.gbl...

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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.