display float

  • Thread starter Thread starter Howard
  • Start date Start date
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
 
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!
 
I tried that it says
No overload for method 'ToString' takes '1' arguments

object.ToString()


There has to be a way to display decimals.
 
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}") %>
 
Thanks it works now

What is the difference between
Eval()?
and
DataBinder.Eval()?
 
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

Similar Threads

Credit Score 5
Excel Applying Code to a Column 0
Using VBA to trigger a certain slide 0
Excel Excel Vab Display contents of Cell 2
Excel Excel conundrum - I've tried and tried, but 10
Count and Group By 3
GridView inside a FormView 4
CSS menu 1

Back
Top