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 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 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. 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. 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 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; 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); ?> Link to comment https://forums.phpfreaks.com/topic/87322-show-number-sign/#findComment-446817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.