Phpfr3ak Posted October 5, 2010 Share Posted October 5, 2010 Hi, basically i have data in my database i want to represent as cash, i currently put the dollar sign infront of each echo which is fine, but how would i go about adding , to the php code itself as you cannot do this from the sql database.. Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 5, 2010 Share Posted October 5, 2010 do you mean echo "$" . $value; ? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 echo '$'.$value; echo "\$$value"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 5, 2010 Share Posted October 5, 2010 It could be done directly in the query, if you want to do it that way. It may end up being less code if you have a lot of values to display. SELECT CONCAT('$', FORMAT(`field`, 2)) AS alias FROM `table` WHERE `some_field` = 'some_parameter' EDIT: There may be other considerations, such as precision and rounding, no matter which method you use. Quote Link to comment Share on other sites More sharing options...
Phpfr3ak Posted October 6, 2010 Author Share Posted October 6, 2010 Sorry i wasn;t very clear, what i actually meant was numbers that i currently want shown as money form are shown as say 345678 where as id like them to be shown as 345,678 Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 6, 2010 Share Posted October 6, 2010 have you looked at http://php.net/manual/en/function.money-format.php Quote Link to comment Share on other sites More sharing options...
Phpfr3ak Posted October 6, 2010 Author Share Posted October 6, 2010 Thanks for that i've done the following, only problem is it shows the noto as say 239,952,380.00 is there a way to remove the . as its not needed in the manner im using it and it looks out of place, thanks. <?php echo number_format($data2['noto'], 2, '.', ','); ?></strong>xp)</span></td> Quote Link to comment Share on other sites More sharing options...
gevensen Posted October 6, 2010 Share Posted October 6, 2010 if i remember right you either make the decila 0 or NULL in number format as below <?php echo number_format($data2['noto'], 2, '.', ','); ?> <?php echo number_format($data2['noto'], 0, '.', ','); ?> <?php echo number_format($data2['noto'], 0, '', ','); ?> Quote Link to comment 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.