darkfreaks Posted September 27, 2007 Share Posted September 27, 2007 ok when your first see it it says division by zero on line 14 which is <?php $total=$weight/$heightwo *703; ?> also when it divides i get something like "Your Body Mass Index is 9097.64705882%" i want to format the number so the dot is the second digit to the left like 00.00% Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 okay i fixed the division by zero problem does anyone know how i would use the format_number function to make it 00.00% ? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 can i even do this with this function? ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 is there a way i can return the total and if it returns 0.000000% it converts it to 00% ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 27, 2007 Share Posted September 27, 2007 http://ca.php.net/manual/en/function.sprintf.php Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 ok so now i got sprintf ('01.2f',$total); and it just displays blank? ??? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 could someone paste aan example as how i would do it via sprintf? Quote Link to comment Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 If you want it echo'd at the same time you need to use printf(). printf ('%01.2f',$total); Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 27, 2007 Author Share Posted September 27, 2007 now i get 2166.00% how would i make it so it is like 00.00% Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 29, 2007 Share Posted September 29, 2007 now i get 2166.00% how would i make it so it is like 00.00% Do you mean how would you get that example value to display as 21.66%? If so, try the old divide by 100 trick. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Author Share Posted September 29, 2007 my entire code is below i want it to calculate Body Mass Index Formula if someone can look one up and see if i have done my math correctly? <?php $height= trim($_POST['height']); $weight=trim($_POST['weight']); $height=str_replace(',','',$height); $height=str_replace('.','',$height); $height=strip_tags($height); $weight=strip_tags($weight); $weight=str_replace(',','',$weight); $weight=str_replace('.','',$weight); if ($_POST['height']||$_POST['weight']=="true") { $weighttwo=$weight*100; $total=$weighttwo/$height;} if($_POST['weight']=="") {$error['weight']="Please enter a weight!";} else {unset($error['weight']);} if($_POST['height']=="") {$error['height']="Please enter a height!";} else {unset($error['height']);} if($error) {?> <form method="POST"> <b>Height(inches):</b><input name="height" type="text" size="3"><?php if ($_POST) { echo $error['height'];} ?><b>Weight(lbs.):</b><input name="weight" type="text" size="3"><?php if ($_POST) { echo $error['weight'];} ?> <input type="submit" name="Calculate!" value="Calculate!"> </form> <?php } else{echo "Your Mass Body Index is"; echo $total; echo "%"; } ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Author Share Posted September 29, 2007 nvm the formula is all messed up its sposed to be $weight/$height*$height*703 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 29, 2007 Author Share Posted September 29, 2007 now i get Your Mass Body Index is160284% i think im still doing something wrong the forumula is BMI = ( Weight in Pounds / ( Height in inches ) x ( Height in inches ) ) x 703 Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 29, 2007 Share Posted September 29, 2007 I suspect the real formula is: BMI = (weight in pounds * 703) / (height in inches * height in inches) Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Author Share Posted September 30, 2007 ok so i put $bmi= ($weight*703)/($height*2); and now its getting abit morre realistic i get your BMi is 1083% i want to knock it down to a 2 digit whole so its like 1-50 percent and even then i dont think its adding up right or something because it would be 10.83 percent and at my current weight and height it should come out to 29.9 percent Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 30, 2007 Share Posted September 30, 2007 No, not height times two. height * height. Basic math Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Author Share Posted September 30, 2007 ok its working now my fault now i get 29.2712345 how do i get rid of the .stuff? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 30, 2007 Share Posted September 30, 2007 printf(); Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Author Share Posted September 30, 2007 ok so i did printf($total); and i still see no diff? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 30, 2007 Share Posted September 30, 2007 Try again. Take a few minutes to re-read the useful contributions in this thread. Take a deep breath. All the help you need is in this thread. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted September 30, 2007 Author Share Posted September 30, 2007 thanks to you all this thread will be closed in 2 seconds Quote Link to comment Share on other sites More sharing options...
neylitalo Posted September 30, 2007 Share Posted September 30, 2007 ok so i put $bmi= ($weight*703)/($height*2); and now its getting abit morre realistic i get your BMi is 1083% i want to knock it down to a 2 digit whole so its like 1-50 percent and even then i dont think its adding up right or something because it would be 10.83 percent and at my current weight and height it should come out to 29.9 percent If you'll notice, AndyB didn't say "height * 2", he said "height * height". There's a rather significant difference there. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 30, 2007 Share Posted September 30, 2007 If you'll notice, AndyB didn't say "height * 2", he said "height * height". There's a rather significant difference there. Only if height != 2 Quote Link to comment 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.