mkosmosports Posted January 23, 2008 Share Posted January 23, 2008 Hey, Is there any way to show the number sign of any number (ie. if its positive, show the + before it, if its zero, show nothing and if its negative show -) aside from the obvious if/else condition? Perhaps a built-in function... Thanks in advance. mkosmosports Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/ Share on other sites More sharing options...
kts Posted January 23, 2008 Share Posted January 23, 2008 Not familiar with one but... and i didnt read the line sorry Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446624 Share on other sites More sharing options...
mkosmosports Posted January 23, 2008 Author Share Posted January 23, 2008 Ok. Ill keep looking around and let you know when I find something. Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446644 Share on other sites More sharing options...
freebsdntu Posted January 23, 2008 Share Posted January 23, 2008 I am not sure if there is such a built in function. But I believe you can surely write one yourself. Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446647 Share on other sites More sharing options...
priti Posted January 23, 2008 Share Posted January 23, 2008 thought of sharing this link http://in.php.net/number-format Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446649 Share on other sites More sharing options...
Ken2k7 Posted January 23, 2008 Share Posted January 23, 2008 Well it's not hard. if ($num > 0) echo "+".$num; Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446653 Share on other sites More sharing options...
sasa Posted January 23, 2008 Share Posted January 23, 2008 try <?php $a = 123.56; echo $b = sprintf('%+.2f', $a),"\n"; echo $c = sprintf('%+d', $a); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446817 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.