gtilflm
gtilflm

Reputation: 1465

PHP - number_format and rounding

The number_format function in PHP seems to round by default. My understanding is that this function is useful for separating every three numbers with a comma. Like 1403423 becomes 1,404,423 when using number_format.

So, if I have a large number that I want rounded to two decimal places, how can I do this and still have the commas properly displayed?

Desired behavior: 12042.529 --> 12,042.53

Upvotes: 0

Views: 2966

Answers (1)

sskoko
sskoko

Reputation: 839

$a=12042.529;
echo number_format($a,2,'.',',');

Upvotes: 1

Related Questions