theycallmepj Posted February 28, 2007 Share Posted February 28, 2007 Here is the main part of a page I have. The person puts in a number, and this puts out a bunch of numbers. Is it possible to show negative numbers red, and positive numbers blue? How would I do that? <? //If the submit button has been pressed if (isset($_POST['submit'])) { /* Definitions */ $salary = $_POST['salary']; $hundred_percent = 274.13; $sixty_percent = 164.48; $pit = 0.011; $pit_amount = $salary*$pit; $difference_hundred = $hundred_percent-$pit*$salary; $difference_sixty = $sixty_percent-$pit*$salary; /* End Definitions */ echo "<br /><table width=\"360\"><tr><td>"; echo "The Company recommends a PIT at a minimum exclusion of 1.1%."; echo "With your salary level of <b>$$salary</b> you can expect to remit a personal income tax of <b>$$pit_amount</b>."; echo "With a 100% tax collection, as a homestead eligible household, you will recieve a property tax reduction of <b>$$hundred_percent</b>, a difference of <b>$$difference_hundred</b>."; echo "With a 60% tax collection rate, you will recieve a tax reduction of <b>$$sixty_percent</b>, a difference of $<b>$difference_sixty</b>."; echo "</td></tr></table>"; } ?> <form action="eit.php" method="post"> <p> Salary:<br /> <input type="text" name="salary" size="20" maxlength="40" value="" /><br /> <i><b>Do NOT put dollar signs, commas, spaces, etc...The only things allowed are numbers and decimal points</b></i> </p> <input type="submit" name="submit" value="GO!" /> </form> Thanks Quote Link to comment Share on other sites More sharing options...
theycallmepj Posted February 28, 2007 Author Share Posted February 28, 2007 Depending on what number is inputed, some numbers will come out positive and some will come out negative. I want each a different color. Quote Link to comment Share on other sites More sharing options...
Orio Posted February 28, 2007 Share Posted February 28, 2007 Something like this maybe? Just pass the numbers through this function and it will output them with the color: <?php function echo_num($number) { if($number > 0) echo "<font color=\"blue\">".$number."</font>"; elseif($number < 0) echo "<font color=\"red\">".$number."</font>"; else echo $number; } ?> Orio. Quote Link to comment Share on other sites More sharing options...
theycallmepj Posted February 28, 2007 Author Share Posted February 28, 2007 I should have thought of that.....haha Thanks for the help 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.