Results 1 to 6 of 6

Thread: number changing to higher integer

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default number changing to higher integer

    hi there,
    I know that is possible to make numbers 1.3 to convert to ~1 (2.6 ~ 3 etc...)
    But is it possible to change them to higher side when they are 1.1 ; 1.2; 1.3, 5.1, They would be like 1; 1; 1; 5;
    If you need more specific details, ask thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Looks like you contradicted yourself. You said "higher side", but then you rounded them down, do you mean:

    If you have 1.2 it will go to 2?

    If so, handy function:

    PHP Code:
    <?php
    $number 
    1.2;

    $number ceil($number);
    echo 
    $number// Ouputs 2
    ?>
    Or if you mean the opposite:

    PHP Code:
    <?php
    $number 
    1.8;

    $number floor($number);
    echo 
    $number// Ouputs 1
    ?>
    Or if you mean just rounding in general:

    PHP Code:
    <?php
    $number 
    1.8;

    $number round($number);
    echo 
    $number// Ouputs 2
    ?>
    Hopefully one of the above is what you want. If not, just say.

  3. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    thanks... first one fits my needs

  4. #4
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    i have trying to find command which makes number 33.333333333 to 33.33, but failed in english can someone help with this? it's like 2 numbers after point.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    See:

    http://php.net/manual/en/function.round.php

    particularly:

    Example #1 round() examples
    <?php
    echo round(3.4); // 3
    echo round(3.5); // 4
    echo round(3.6); // 4
    echo round(3.6, 0); // 4
    echo round(1.95583, 2); // 1.96
    echo round(1241757, -3); // 1242000
    echo round(5.045, 2); // 5.05
    echo round(5.055, 2); // 5.06

    ?>



    Example #2 mode() examples
    <?php
    echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10
    echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
    echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
    echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9

    echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9
    echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
    echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
    echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
    ?>
    So I image you would want something like:

    Code:
    $number = round($number, 2, PHP_ROUND_HALF_DOWN);
    or:

    Code:
    $number = round($number, 2);
    perhaps even:

    Code:
    $number = 33.333333;
    $number = ceil($number*100);
    echo $number/100;
    Last edited by jscheuer1; 12-30-2009 at 03:25 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    OK, thanks

Bookmarks

Posting Permissions

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