I'm super confused trying to format this guys!! I'm making a shopping cart that tacks on 3%. I need the "cctotal" variable to have 2 numbers trailing the decimal (ex - 1.00, 5.25, 9.50). I don't care about a comma for a thousand dollar marker.
Sometimes, when I add the 3%, the number gets ugly, like 5.192059, I need it to be able to round up/down accordingly. Also, if it's just an even dollar amount (5.00, 10.00) or there is nothing in the tenth's place (5.10, 10.50) that is will show the 2nd trailing zero.
$onlinead = $onlinead * 1.03;
$cctotal = number_format($onlinead);
Right now, that won't give me trailing zeros I want!
All About the Money
Moderator: General Moderators
- SheDesigns
- Forum Commoner
- Posts: 42
- Joined: Tue Nov 18, 2008 9:51 am
- Location: Buffalo, NY
Re: All About the Money
http://bg2.php.net/round
http://bg2.php.net/manual/en/function.money-format.php
http://bg2.php.net/sprintf
There are too many ways
http://bg2.php.net/manual/en/function.money-format.php
http://bg2.php.net/sprintf
There are too many ways
There are 10 types of people in this world, those who understand binary and those who don't
Re: All About the Money
You're on the right track, just keep in mind that number_format can take additional parameters to handle this situation.
Take a look at this example:
This returns:
5.19
It will also return two trailing 0's (if there is nothing else.)
Good luck.
Take a look at this example:
Code: Select all
$cctotal = number_format(5.192059, 2, ".", ",");
echo $cctotal; 5.19
It will also return two trailing 0's (if there is nothing else.)
Good luck.