ajc1502 Posted June 1, 2012 Share Posted June 1, 2012 Hi New but learning fast... I am trying to achieve echo or printing a $variable which is a number. I would like it to display red if negative or black is positive! I also need to round the number to 0. i.e -34.32345 becomes -34 I have achieved each independently but if I try and add rounding it breaks the code??? So I need to know how to add rounding to the variable $variancemonth in the following code. <?php if ($differencemonth <= 0 ){ print "Variance Month <font color=\"red\">£$differencemonth</font>"; } else { print "Variance Month <font color=\"000000\">£$differencemonth</font>"; } ?> Any help would be appreciated. Regards Andy ps I can find examples of both rounding and formatting independently but not used together. Quote Link to comment https://forums.phpfreaks.com/topic/263482-php-if-else-rounding-and-conditional-formatting-frustration/ Share on other sites More sharing options...
trq Posted June 1, 2012 Share Posted June 1, 2012 <?php if ($differencemonth <= 0 ){ print "Variance Month <font color=\"red\">£" . round($differencemonth) . "</font>"; } else { print "Variance Month <font color=\"000000\">£" . round($differencemonth) . "</font>"; } Quote Link to comment https://forums.phpfreaks.com/topic/263482-php-if-else-rounding-and-conditional-formatting-frustration/#findComment-1350293 Share on other sites More sharing options...
ajc1502 Posted June 1, 2012 Author Share Posted June 1, 2012 Thank you so much, had 3 hours on that one You have a good day.. Quote Link to comment https://forums.phpfreaks.com/topic/263482-php-if-else-rounding-and-conditional-formatting-frustration/#findComment-1350298 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.