user1856596
user1856596

Reputation: 7243

number_format return the wrong value?

This is my code:

$subTotal = number_format($subTotal, 2);

In $subTotal I had a value like 1,233.00 as a string. The return value was 1.00, which of course is wrong. So I tried something else:

$subTotal = number_format($subTotal, 2, '.', ',');

Result is still the same. How can I make it work with a , as thousand separator?

Thanks!

Upvotes: 0

Views: 685

Answers (1)

John Conde
John Conde

Reputation: 219934

Remove the commas before you call number_format()

$subTotal = number_format(str_replace(',', '', $subTotal), 2);

Upvotes: 1

Related Questions