Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("SOT", typeof(Decimal));
        dt.Columns.Add("SVT", typeof(Decimal));
        dt.Columns.Add("SCT", typeof(Decimal));
        dt.Rows.Add(12.22, 23.44, 22.00);
        dt.Rows.Add(2.20, 23.00, 22.23);
        dt.Rows.Add(12.00, 23.20, 22.05);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    catch (Exception d)
    {
        Response.Write(d.Message.ToString());
    }
}

DataTable can take values like {12,10.5} instead of {12.00,10.50}. Is there any method to insert into DataTable with exactly two decimal places.
Posted

You know, 12 and 12.00 are the same Decimal value.
You shouldn't bother about number representation inside the database and do your formatting job on the GUI.
 
Share this answer
 
Comments
cmathi1892 11-Sep-15 9:10am    
No. i am displayig like 12.00 is to looks like time.
CPallini 11-Sep-15 9:12am    
So?
hypermellow 11-Sep-15 9:46am    
Sensible advice ... my 5 :-)
George Jonsson 11-Sep-15 12:17pm    
Good advice. My 5 as well.
VB
Try like below:

dt.Rows.Add(12.22m, 23.44m, 22.00m);

or

Math.Round((Double)12.22, 2)
 
Share this answer
 
Comments
cmathi1892 11-Sep-15 9:40am    
Thanks dude. It's Working.
George Jonsson 11-Sep-15 12:24pm    
I know this answers the question at hand, but it is much better to do the formatting in the presentation layer using String.Format().
Just like Solution 1 suggests.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900