Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Decimal Place Problem

  • 27-02-2008 01: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,266 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,673 ✭✭✭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