display float

H

Howard

I have a databind in a repeater control
<%#Eval("Score")%>

Score is a float
float Score = 3.2;
However the html output is always 3 I cannot make it display 3.2.

PLease help,
Howard
 
N

Nathan Sokalski

Try this:

<%#Eval("Score").ToString("n")%>

If you need to specify how many decimal places to use, do the following (the
following will use 10 decimal places, adjust this to your preference):

<%#Eval("Score").ToString("n10")%>

If you have any questions, feel free to ask. You can also see Visual
Studio's section on "Format Specifiers" for more detail. Good Luck!
 
H

Howard

I tried that it says
No overload for method 'ToString' takes '1' arguments

object.ToString()


There has to be a way to display decimals.
 
N

Nathan Sokalski

Try this (my suggestion is not really the one I would have used, but it
looked like the one you would have preferred, but I admit I didn't actually
try that one):

<%# DataBinder.Eval(Container, "DataItem.Score","{0:n}") %>

or to specify the number of decimals:

<%# DataBinder.Eval(Container, "DataItem.Score","{0:n10}") %>
 
N

Nathan Sokalski

I'm not sure there is a difference in this case, but in some cases they are
methods with the same name from different classes. I have been taught to use
DataBinder just to be safe, but if you prefer you can probably use just
Eval(). For more detail, see the documentation.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top