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. Quote 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 Quote 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 Quote 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; ?> Quote 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. Quote 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. Quote 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? Quote 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, '.', ''); Quote Link to comment https://forums.phpfreaks.com/topic/50733-solved-need-a-placeholder/#findComment-251553 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.