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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Decimal Place Problem

  • 27-02-2008 12:59am
    #1
    Registered Users, Registered Users 2 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,125 Mod ✭✭✭✭AlmightyCushion


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,571 ✭✭✭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