469,913 Members | 2,683 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Formatting Numbers for a DropDownList

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
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 26 '07 #1
3 2326
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uS**************@TK2MSFTNGP02.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

Sep 26 '07 #2
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...

[cross-posting removed and top-posting corrected]
>.ToString().TrimEnd('0');
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.
If you don't want to use the OnDataBinding event, why not just return the
data from the database in the format that you require it...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 27 '07 #3
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uS**************@TK2MSFTNGP02.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

Sep 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Sutor | last post: by
7 posts views Thread by ilona | last post: by
reply views Thread by George Durzi | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
5 posts views Thread by Mike P | last post: by
4 posts views Thread by koonda | last post: by
3 posts views Thread by sparks | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.