quillspirit Posted May 9, 2007 Share Posted May 9, 2007 Ok, so I have variable $x = "123.395"; I use $x = round($x, 2); and come up with: 123.4 All is fine up to this point, except what I need to do is show that as a dollar value (for shopping cart)... so I want to show the missing placeholder 0 for 1/100ths. I don't want a comma for 1,000.00 and do not want a $ sign to display... so I don't think money_format() is what I need. The end result for $x needs to be: 123.40 Thanks. Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/ Share on other sites More sharing options...
redarrow Posted May 9, 2007 Share Posted May 9, 2007 number_format() you need ok link http://uk2.php.net/number_format Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-249409 Share on other sites More sharing options...
quillspirit Posted May 9, 2007 Author Share Posted May 9, 2007 I forgot to mention... sometimes $x is already fine at 123.45 Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-249411 Share on other sites More sharing options...
redarrow Posted May 9, 2007 Share Posted May 9, 2007 <?php $x = "123.395"; $x = round($x, 2); $x=number_format($x,2); echo $x; ?> Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-249415 Share on other sites More sharing options...
quillspirit Posted May 9, 2007 Author Share Posted May 9, 2007 Excellent - shoulda known it would be that simple. It usually is. Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-249423 Share on other sites More sharing options...
quillspirit Posted May 10, 2007 Author Share Posted May 10, 2007 Problem... it is inserting commas for thousands - 123,456,789.00 breaking my calculations. Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-249424 Share on other sites More sharing options...
quillspirit Posted May 11, 2007 Author Share Posted May 11, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-250225 Share on other sites More sharing options...
quillspirit Posted May 12, 2007 Author Share Posted May 12, 2007 Took me a while, but now this is solved: To remove the separator commas from the output, if $x > 999 (so you can continue using $x for calculations): $x=number_format($x, 2, '.', ''); Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-251553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.