Home > DeveloperSection > Forums > Restrict number of decimals to be displayed from DB
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    August-22-2014 1:01 AM

 C# C# 
Ratings:


 1 Reply(s)
 490  View(s)
Rate this:

I am fetching some values from my DB.

The columns are of float type and are being displaced in DataList in the following manner.

<ItemTemplate>

    <tr>

    <td style="width:200px;text-align:left"> Item1: <%#Eval("Item1") %>  |  Item2: <%#Eval("Item2") %></td>

    </tr>

    </ItemTemplate>

I have to restrict the number of decimal values being displayed int he data list to 3.

How can I do that here?

In the code-behind, the data is being fetched into the DataTable as follows.

SqlDataAdapter adp = new SqlDataAdapter("Retrieve", ConfigurationManager.ConnectionStrings["cn"].ConnectionString);

             DataSet ds = new DataSet();

             adp.SelectCommand.CommandType = CommandType.StoredProcedure;

             adp.SelectCommand.Parameters.Add("@s1", SqlDbType.NVarChar, 255).Value = strategies;

             adp.SelectCommand.Parameters.Add("@s2", SqlDbType.NVarChar, 255).Value = DropDownList1.SelectedItem.ToString();

             adp.Fill(ds);

             DataList1.DataSource = ds;

             DataList1.DataBind();



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-22-2014 1:59 AM

HI jeet, 
try this:

Eval("Item1", {0:#0.000})


Don't want to miss updates? Please click the below button!

Follow MindStick