Jump to content

PHP if else rounding and conditional formatting frustration


ajc1502

Recommended Posts

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.

Link to comment
Share on other sites

<?php
if ($differencemonth <= 0 ){ 
    print "Variance Month <font color=\"red\">£" . round($differencemonth) . "</font>"; 
} else { 
    print "Variance Month <font color=\"000000\">£" . round($differencemonth) . "</font>"; 
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.