koohoofoo Posted February 11, 2014 Share Posted February 11, 2014 I am VERY new to PHP and I am working on an assignment for school and I have most of the assignment done, but the only thing that I can not figure out is the last step. It says to use the round() function to display the Celsius temperature to one place after the decimal point. No matter where I look I can not figure out how to do this. The rest of my code works well. Can anyone help me and show me how to do this round statement? heres what I have: <?php$fTemp = 0;while ($fTemp <= 100) { $cTemp = ($fTemp - 32) * .55; echo $fTemp." Fahrenheit is equal to ".$cTemp." Celsius<br />"; $fTemp++;}?> Quote Link to comment https://forums.phpfreaks.com/topic/286099-can-anyone-help-a-newbie-please/ Share on other sites More sharing options...
koohoofoo Posted February 11, 2014 Author Share Posted February 11, 2014 When I run the code....This is my output..... 0 Fahrenheit is equal to -17.6 Celsius1 Fahrenheit is equal to -17.05 Celsius2 Fahrenheit is equal to -16.5 Celsius3 Fahrenheit is equal to -15.95 Celsius4 Fahrenheit is equal to -15.4 Celsius5 Fahrenheit is equal to -14.85 Celsius6 Fahrenheit is equal to -14.3 Celsius7 Fahrenheit is equal to -13.75 Celsius8 Fahrenheit is equal to -13.2 Celsius9 Fahrenheit is equal to -12.65 Celsius10 Fahrenheit is equal to -12.1 Celsius11 Fahrenheit is equal to -11.55 Celsius12 Fahrenheit is equal to -11 Celsius13 Fahrenheit is equal to -10.45 Celsius14 Fahrenheit is equal to -9.9 Celsius15 Fahrenheit is equal to -9.35 Celsius16 Fahrenheit is equal to -8.8 Celsius17 Fahrenheit is equal to -8.25 Celsius18 Fahrenheit is equal to -7.7 Celsius19 Fahrenheit is equal to -7.15 Celsius20 Fahrenheit is equal to -6.6 Celsius21 Fahrenheit is equal to -6.05 Celsius22 Fahrenheit is equal to -5.5 Celsius23 Fahrenheit is equal to -4.95 Celsius24 Fahrenheit is equal to -4.4 Celsius25 Fahrenheit is equal to -3.85 Celsius26 Fahrenheit is equal to -3.3 Celsius27 Fahrenheit is equal to -2.75 Celsius28 Fahrenheit is equal to -2.2 Celsius29 Fahrenheit is equal to -1.65 Celsius30 Fahrenheit is equal to -1.1 Celsius31 Fahrenheit is equal to -0.55 Celsius32 Fahrenheit is equal to 0 Celsius33 Fahrenheit is equal to 0.55 Celsius34 Fahrenheit is equal to 1.1 Celsius35 Fahrenheit is equal to 1.65 Celsius36 Fahrenheit is equal to 2.2 Celsius37 Fahrenheit is equal to 2.75 Celsius38 Fahrenheit is equal to 3.3 Celsius39 Fahrenheit is equal to 3.85 Celsius40 Fahrenheit is equal to 4.4 Celsius41 Fahrenheit is equal to 4.95 Celsius42 Fahrenheit is equal to 5.5 Celsius43 Fahrenheit is equal to 6.05 Celsius44 Fahrenheit is equal to 6.6 Celsius45 Fahrenheit is equal to 7.15 Celsius46 Fahrenheit is equal to 7.7 Celsius47 Fahrenheit is equal to 8.25 Celsius48 Fahrenheit is equal to 8.8 Celsius49 Fahrenheit is equal to 9.35 Celsius50 Fahrenheit is equal to 9.9 Celsius51 Fahrenheit is equal to 10.45 Celsius52 Fahrenheit is equal to 11 Celsius53 Fahrenheit is equal to 11.55 Celsius54 Fahrenheit is equal to 12.1 Celsius55 Fahrenheit is equal to 12.65 Celsius56 Fahrenheit is equal to 13.2 Celsius57 Fahrenheit is equal to 13.75 Celsius58 Fahrenheit is equal to 14.3 Celsius59 Fahrenheit is equal to 14.85 Celsius60 Fahrenheit is equal to 15.4 Celsius61 Fahrenheit is equal to 15.95 Celsius62 Fahrenheit is equal to 16.5 Celsius63 Fahrenheit is equal to 17.05 Celsius64 Fahrenheit is equal to 17.6 Celsius65 Fahrenheit is equal to 18.15 Celsius66 Fahrenheit is equal to 18.7 Celsius67 Fahrenheit is equal to 19.25 Celsius68 Fahrenheit is equal to 19.8 Celsius69 Fahrenheit is equal to 20.35 Celsius70 Fahrenheit is equal to 20.9 Celsius71 Fahrenheit is equal to 21.45 Celsius72 Fahrenheit is equal to 22 Celsius73 Fahrenheit is equal to 22.55 Celsius74 Fahrenheit is equal to 23.1 Celsius75 Fahrenheit is equal to 23.65 Celsius76 Fahrenheit is equal to 24.2 Celsius77 Fahrenheit is equal to 24.75 Celsius78 Fahrenheit is equal to 25.3 Celsius79 Fahrenheit is equal to 25.85 Celsius80 Fahrenheit is equal to 26.4 Celsius81 Fahrenheit is equal to 26.95 Celsius82 Fahrenheit is equal to 27.5 Celsius83 Fahrenheit is equal to 28.05 Celsius84 Fahrenheit is equal to 28.6 Celsius85 Fahrenheit is equal to 29.15 Celsius86 Fahrenheit is equal to 29.7 Celsius87 Fahrenheit is equal to 30.25 Celsius88 Fahrenheit is equal to 30.8 Celsius89 Fahrenheit is equal to 31.35 Celsius90 Fahrenheit is equal to 31.9 Celsius91 Fahrenheit is equal to 32.45 Celsius92 Fahrenheit is equal to 33 Celsius93 Fahrenheit is equal to 33.55 Celsius94 Fahrenheit is equal to 34.1 Celsius95 Fahrenheit is equal to 34.65 Celsius96 Fahrenheit is equal to 35.2 Celsius97 Fahrenheit is equal to 35.75 Celsius98 Fahrenheit is equal to 36.3 Celsius99 Fahrenheit is equal to 36.85 Celsius100 Fahrenheit is equal to 37.4 Celsius I just need to figure out how to use the round() statement to get it to display the Celsius temp to one place after the decimal point. Quote Link to comment https://forums.phpfreaks.com/topic/286099-can-anyone-help-a-newbie-please/#findComment-1468430 Share on other sites More sharing options...
requinix Posted February 11, 2014 Share Posted February 11, 2014 Well, you're not trying to use it anywhere so I don't know what to tell you about why it's not working... round float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] ) Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default). Quote Link to comment https://forums.phpfreaks.com/topic/286099-can-anyone-help-a-newbie-please/#findComment-1468434 Share on other sites More sharing options...
koohoofoo Posted February 11, 2014 Author Share Posted February 11, 2014 That is what I was needing help with. I can not figure out where it needs to be or even how to do it. I have looked in my book and online and I just dont understand it. Quote Link to comment https://forums.phpfreaks.com/topic/286099-can-anyone-help-a-newbie-please/#findComment-1468435 Share on other sites More sharing options...
requinix Posted February 11, 2014 Share Posted February 11, 2014 $cTemp is the variable holding the Celsius value. You can round it in two places: 1. When you calculate it 2. When you output it #2 is the best choice: leave the math be as exact as possible and make it only show the one decimal place. That idea of not modifying a value early on and instead waiting until you need to do so (and to do it without permanently modifying the original value) is a good habit to get into as it will help you later with other concepts. Instead of outputting $cTemp, output the result of the round() function; "$val" is the value and "$precision" is the number of decimal places to round to. round($cTemp, 1) Quote Link to comment https://forums.phpfreaks.com/topic/286099-can-anyone-help-a-newbie-please/#findComment-1468439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.