Jump to content

Number color


theycallmepj

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/40528-number-color/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/40528-number-color/#findComment-196114
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.