ONYX
ONYX

Reputation: 5859

php round number include zero if .50

I want to round a number for e.g 269.00 and I round it like

round($price, 2)

which outputs 269 but when I have a value like 269.50 it ouputs 269.5 and I want to have the zero at the end this is for pricing products

Upvotes: 9

Views: 6425

Answers (1)

icktoofay
icktoofay

Reputation: 129109

Use number_format afterwards:

$price = number_format(round($price, 2), 2);

This also adds commas as thousands separators.

Upvotes: 17

Related Questions