Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Decimal Place Problem

Options
  • 27-02-2008 1:59am
    #1
    Registered Users Posts: 325 ✭✭


    Hi

    I'm using MySQL, VS2005 and C#

    I'm getting the average of the Average column and this is working fine

    string sql = "SELECT AVG(Average) FROM studentvillageaverage";


    I am than displaying this to a label on the webpage with

    Session["StudentVillageAverage"] = MyReader["AVG(Average)"];
    Label4.Text = Session["StudentVillageAverage"].ToString();



    The problem I'm having is that when this is displaying its leaving 4 decimal points after the number, i.e. 4.0000

    What do i need to put in to just display 4.0?


Comments

  • Moderators, Education Moderators, Technology & Internet Moderators Posts: 35,079 Mod ✭✭✭✭AlmightyCushion


    Try parsing it to an int. e.g. Label4.Text = int.Parse(Session["StudentVillageAverage"].ToString());


  • Registered Users Posts: 413 ✭✭ianhobo


    .ToString() accepts parameters in " " to modify the output as format specifiers

    if you call blah.ToString("N2") it should give you your result to two decimal places. Similarly "X" changes to upper case hex (if i remember correctly!)


  • Registered Users Posts: 325 ✭✭doyler442


    I tried both these but I'm getting the error

    Error 1 No overload for method 'ToString' takes '1' arguments


    Any more ideas?


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    doyler442 wrote: »
    string sql = "SELECT AVG(Average) FROM studentvillageaverage";
    The MySQL FORMAT() function might work.
    string sql = "SELECT FORMAT(AVG(Average),1) FROM studentvillageaverage";
    


Advertisement