4. Math Functions I


#1



<?php
// Try rounding a floating point number to an integer
// and print it to the screen
$round = round(3.154);
print $round;
?>



<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen
$roundDecimal = round(1.2365, 3);
print $roundDecimal;
?>


then : Oops, try again. Did you remember to use round() in your code?


#2

You haven't done anything wrong that I can see. I suggest refreshing the page.


#3

Mine does not work either except that I receive the error "Oops, try again. Your first call to round() should print an integer."


#4

I have the same problem with my code...



<?php
// Try rounding a floating point number to an integer
// and print it to the screen
$round = round(1.298);
print $round;

$rounddecimal =  round(1.298, 4);
print $rounddecimal;
?>
</p>
<p>
<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen

?>
</p>


#5

echo(round(7.055,3));

take this piece of code and it will run. This exercise is a little bit buggy:(


#6

I have this exact same problem!


#7

well it should be (round_decimal) not rounddecimal......


#8

Just a little Buggy, this code should pass.

<html>
    <p>
    <?php
    print round(M_PI)
    ?>
    </p><p>
    <?php
    print round(M_PI,3)
    ?>
    </p>
</html>

#9

It is buggy because that should work, I noticed that the only way it will work is if it's on one line.

print or echo

echo (round(3.153,3))


#10

I'm having the weirdest problem!



<?php
print rand(1,202101201021);

?>
</p>
<p>
<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$name='Joy Kaufman';
print strlen($name);
print rand(0,10);


?>
</p>

On the last line before ending php with ?>, you will see I have written print rand(0,10);. In my console it keeps returning numbers over 100. Am I missing something here?(That is a direct snippet.)


#11

how to print intiger.


#12

This code worked, I had the same problem as everybody :slight_smile:


#13



<?php
// Try rounding a floating point number to an integer
// and print it to the screen
$int = round(10.09,0);
print $int;

?>
</p>
<p>
<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen
$float = round(M_PI, 3);
print $float;

?>

NOTE: M_PI is a PHP constant that i


note :- In the first round function, put zero in decimal place $int = round(10.09, 0); !!


#14



<?php
print round(M_PI)
?>


<?php
print round(M_PI,3)
?>


this code is working.


#16



<?php
print round(M_PI)
?>


<?php
print round(M_PI,3)
?>


finally error free code and was able to move forward in next lessons :slight_smile:


#17

It's as simple as this

    <?php
    // Try rounding a floating point number to an integer
    // and print it to the screen
    $round=round(M_PI);
    print $round
    ?>
    </p>
    <p>
    <?php
    // Try rounding a floating point number to 3 decimal places
    // and print it to the screen
    $round_decimal=round(M_PI,3);
    print $round_decimal;
    ?>

#18

Common mistake here, most of your code is correct. The only problem is that you wrote $roundDecimal like this. Try not to link $roundDecimal like this, it should be wrote like $round_decimal, so don't worry just a simple mistake. :slight_smile:
Don't go to overboard with the numbers as well, just keep it nice a simple, for example: ...round(1.874, 3);.
Hope this helped.


#19
<html>
<p>
 <?php
    // Try rounding a floating point number to an integer
    // and print it to the screen
    $round=round(M_PI);
    print $round
    ?>
    </p>
    <p>
    <?php
    // Try rounding a floating point number to 3 decimal places
    // and print it to the screen
    $round_decimal=round(M_PI,3);
    print $round_decimal;
    ?>
    
    </p>
    </html>

This code perfectly worked.