This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

683 points
51518d3e8f002e3e5c001e6c_516962940
Submitted by
Trikyas
about 4 years ago

Math functions 1

I don't know why it's not accepting my code???


<?php
$round = round(MPI);
print $round;
?>


<?php
$round
decimal = round(MPI, 3);
print $round
decimal;
?>

Oops, try again.
Your second call to round() should print a floating point number with exactly 3 digits after the decimal.


2 votes

permalink

<?php
// Try rounding a floating point number to an integer
// and print it to the screen
// Round pi down from 3.1416...

$round = round(M_PI);

print $round;
// This time, round pi to 4 places

?>
</p>
<p>
<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen

$rounddecimal = round(M_PI, 3);
print $rounddecimal;
?>

1005 points
5243be34abf8217812001a77_524156425
Submitted by
Hossam Boss
about 4 years ago

1 Comment

513ec0e25269cd4d0d001740_704847179 RAJAN VERMA almost 4 years ago

thanks


1 vote

permalink

MPI should be M_PI.

 $round = round(M_PI);

You're missing the underscores.

1066 points
4f95db4582a8760003008939_638040855
Submitted by
Chris
about 4 years ago

1 Comment

51518d3e8f002e3e5c001e6c_516962940 Trikyas about 4 years ago

Thankyou


1 vote

permalink

Try to put your statements (print) inside a "p" tag. It worked for me!

1586 points
Fc5cb9b9f8a56b0823e5d1d943b6b250?s=140&d=retro
Submitted by
Fabiano Brandão
about 4 years ago


0 votes

permalink

<html>
<p>
<?php
// Try rounding a floating point number to an integer
// and print it to the screen
$float=1.62455211;
$round=round($float);
print "The number: $float has been rounded to: $round";
?>
</p>
<p>
<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen
$floatDecThree=4.443214567;
$roundThree=round($floatDecThree,3);
print "The number: $floatDecThree has been rounded to: $roundThree";
?>
</p>

The above code looks good, yes? According to the editor it's not, I'm being told that I must round up to 3 decimal places $roundThree=round($floatDecThree,3);

1840 points
Picture
Submitted by
Paul Dolan
about 4 years ago

1 Comment

50c5182086197939c900645b_643754795 autosnap about 4 years ago

I am having issues with this lesson as well, and again, my local host executes and prints my code properly. I could be wrong, of course, but I am pretty sure that these PHP lessons are whack.


0 votes

permalink

I think that lesson is just a bit sensitive to additional text. I was getting the same error when printing output using:

echo "<p>{$roundThree}</p>";

but removing all extra printed text:

echo $roundThree;

made the error go away.

442 points
Picture
Submitted by
Julian Church
over 3 years ago


0 votes

permalink

// Round pi down from 3.1416...
$round = round(M_PI);
print $round; // prints 3

// This time, round pi to 4 places
$rounddecimal = round(MPI, 4);
print $round_decimal; // prints 3.1416

79 points
Bab70c3b801d987986dec59912caf729?s=140&d=retro
Submitted by
sintola
over 2 years ago