Grow your CSS skills. Land your dream job.

how to convert float to this

  • # January 9, 2013 at 3:16 am

    I wonder how can i convert float to …

    $x = 12.548544444
    to
    $x = 12.55

    # January 9, 2013 at 3:43 am

    $x = 12.548544444;
    $answer = round($x*100);
    $answer = $answer/100;
    // $answer == 12.55

    # January 9, 2013 at 5:45 am

    This can be reduced to a single operation by passing a 2nd argument to the round() function.

    $x = 12.548544444;
    $x = round($x, 2);

    The “2″ tells it to round two places past the decimal.

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

    # January 9, 2013 at 6:07 am

    thx very much for helping me

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".