petenaylor Posted December 2, 2010 Share Posted December 2, 2010 Hi all I have a string called $voucher_code which is a value used to deduct or add value to a shopping cart. If the value is a minus I need it to show the minus sign, or if it's a plus value, it needs to show a plus sign. Here's my code: <strong>£ -".number_format(($voucher_code),2)."</strong> How do I modify the above code to show + instead of -- which it does at the moment? Many thanks for your help Pete Link to comment https://forums.phpfreaks.com/topic/220492-changing-from-minus-to-plus/ Share on other sites More sharing options...
laffin Posted December 2, 2010 Share Posted December 2, 2010 $value=-5 $sign=($mod<0)?'-':'+'; $value=abs($value); echo "Sign: {$sign} Value: $value". PHP_EOL; $value=7 $sign=($value<0)?'-':'+'; $value=abs($value); echo "Sign: {$sign} Value: $value". PHP_EOL; Link to comment https://forums.phpfreaks.com/topic/220492-changing-from-minus-to-plus/#findComment-1142332 Share on other sites More sharing options...
petenaylor Posted December 2, 2010 Author Share Posted December 2, 2010 Brilliant! Thanks very much! Link to comment https://forums.phpfreaks.com/topic/220492-changing-from-minus-to-plus/#findComment-1142357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.