• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

[PHP] positive sign after calculations

ckevin

New Member
I have some variables in php and want to display the results with signs ( + or - )

E.g.

PHP:
$c = $a + $b ;

echo $c ;

$c would be any numbers with a + or - sign. E.g. -6 or +7, however, how can I add the + sign when the result is positive?

Thanks!
 
the easiest way is
if($c>0) $c = "+".$c;

negative numbers get a - automaticcaly, i think
 
Last edited:
hohoho, thank you, it works!

I seached PHP website and I find no answer, and your solution save me much time! :)
 
Back
Top