Results 1 to 3 of 3
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default [PHP] Displaying numbers two the whole number

    Does any one know to make it so if the number has a decimal, it displays it to the nearest number. e.g.

    1.4 = 1
    2.7 = 3
    4.3 = 4
    8.8 = 9
    3.1 = 3

    Thanks

  2. #2
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    2,016
    Tokens
    141
    Habbo
    florx

    Latest Awards:

    Default

    PHP Code:
    <?php
    echo round(3.4);         // 3
    echo round(3.5);         // 4
    echo round(3.6);         // 4
    echo round(3.60);      // 4
    echo round(1.955832);  // 1.96
    echo round(1241757, -3); // 1242000
    echo round(5.0452);    // 5.05
    echo round(5.0552);    // 5.06
    ?>
    http://uk2.php.net/round

  3. #3
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by JH View Post
    PHP Code:
    <?php
    echo round(3.4);         // 3
    echo round(3.5);         // 4
    echo round(3.6);         // 4
    echo round(3.60);      // 4
    echo round(1.955832);  // 1.96
    echo round(1241757, -3); // 1242000
    echo round(5.0452);    // 5.05
    echo round(5.0552);    // 5.06
    ?>
    http://uk2.php.net/round
    Thanks, I didn't know what the name of it was
    +Rep

    Hum, just noticed I spelt to as two *slaps self*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •