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

Functions, Part I Forum

View Course » View Exercise

530 points
8bfd984fb29ba6e14e413592fae2d5b6?s=140&d=retro
Submitted by
annemarieny
over 3 years ago

Why won't this pass?

Here's my code

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

$round_decimal = round(36.89737374, 3);
print $round_decimal; 

?>

I get an error message saying "Your first call to round() should print an integer." even though it does.

Any ideas?


0 votes

permalink

What they are saying here is your first call to round function (line 6) is not displaying an integer (a number WITHOUT a decimal or fractional component). Below is the code I wrote to get the correct answer.

1
2
3 <?php
4 // Try rounding a floating point number to an integer
5 // and print it to the screen
6 $round = round(MPI);
7 print $round;
8 ?>
9
10
11 <?php
12 // Try rounding a floating point number to 3 decimal places
13 // and print it to the screen
14 $round = round(M
PI,3);
15 print $round;
16 ?>
17
18

658 points
Picture
Submitted by
Angel Cepeda
over 3 years ago

2 Comments

7fad74fc6b7efc85385b134442c40341?s=140&d=retro Kiernan Maguire about 3 years ago

i did it but it did not work

C014dc9efb19144e0880a72f91ff2d4b?s=140&d=retro jonathan lewis almost 3 years ago

Your Pi needs a _ between M and P


0 votes

permalink

ohh ok, thanks
the website screwed up my code then cause i did pass it somehow o.O

531 points
Picture
Submitted by
G3M|N|
over 3 years ago


0 votes

permalink

Thank you for your help!!

530 points
8bfd984fb29ba6e14e413592fae2d5b6?s=140&d=retro
Submitted by
annemarieny
over 3 years ago


0 votes

permalink

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

$round_decimal = round(36.89737374, 3);
print $round_decimal;

?>

$rounddecimal!!!

i have found this one to be solution for you.

553 points
521d7111f10c6002e10013c2_480497464
Submitted by
Stojan Tashurov
over 3 years ago

1 Comment

5141408c1545c960160027a6_999504877 James Stroehmann about 3 years ago

Works, but wow that does not make sense.