verdrm Posted March 22, 2008 Share Posted March 22, 2008 I would like to bold text if a percentage is closest to 100. Example: $total = ($one / $two) * 100; echo $total; How would I accomplish that using an IF statement or something similar? Link to comment https://forums.phpfreaks.com/topic/97412-is-closest-to/ Share on other sites More sharing options...
wildteen88 Posted March 22, 2008 Share Posted March 22, 2008 What do you define as closest to 100? You can just do a simple range comparison: // if $total greater than 80, wrap $total in bold tags if($total > 80) { echo '<b>' . $total . '</b>'; } // if $total greater than 50 but less than 80, wrap $total in itialic tags elseif($total > 50 && $total < 80) { echo '<i>' . $total . '</i>'; } // $total is than 50, wrap $total in underline tags elseif($total < 50) { echo '<u>' . $total . '</u>'; } Link to comment https://forums.phpfreaks.com/topic/97412-is-closest-to/#findComment-498449 Share on other sites More sharing options...
Barand Posted March 23, 2008 Share Posted March 23, 2008 for each value Calculate $percentage Calculate $diff = abs(100 - $percentage) Smallest $diff is closest to 100. Link to comment https://forums.phpfreaks.com/topic/97412-is-closest-to/#findComment-498550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.