PHP Round With Decimal & Comma $1,000

469 views Asked by At
<?= round(number_format($vehicle->prices['total_rental'], 2, '.', ',') * 0.50,2) ?>

I would like the output to round up to the next 2 decimal places (for money / dollars & cents).

This works great when $vehicle->prices is below $1,000. When $vehicle->prices is above $1,000, it just outputs .50. What is the correct way to round to next hundredth (i.e $1,452.62) ?

I have been trying round and number_format. I cannot seem to get either one to produce the correct output when a comma becomes involved.

1

There are 1 answers

0
pavel On BEST ANSWER

First do an equation, than round and as the last one thing use number_format.

echo number_format(round($vehicle->prices['total_rental'] * .5, 2), 2, '.', ',');