Hi, all,
I'm doing some manipulation with monetary values and am trying to figure out how to get the decimal points to work as intended.
For example, I have some values that are pulled from a MySQL database (the column specifier is "decimal(5,2)", which yields a format like
110.00
for $110. This is what I want. Then, in PHP, I want to calculate a 15 percent discount and subract that from the price.
$cost = $row['cost']; //$110
$discount = 0.15; //15 percent discount
$discounted_amount = $cost * $discount; //returns 16.5
$new_total = $cost - $discounted_amount;
Obviously, this works fine, but the valued returned is
118.5
Is there any easy way to format this number to comply with the standard US currency format, 118.50?
Of course, I'd like this to work for any abitrary cost/discount combination, so if its 104.39 I still get the right number of decimal places.
Thanks for any help 🙂