Reputation:
Iv taken over a very old php project that is still currently in use. Its a custom "shopping" website.
When a product gets ordered it inserts the money value into the database as a string of integers:
2000
which then gets outputted as follows:
R20,00
Using this code
echo number_format($order['order_total'] / 100, 2, ",", "");
My problem is that if an order gets placed to the value of R 15 256.00 The record gets inserted as such:
15256
and gets outputted to the user as:
R 152,56
But it should ultimately show like this
R15, 256.00
I do understand that the problem comes in by dividing the amount by 100 in the above query. If i alter the query then the larger numbers appear fine but the smaller amounts such as R20,00 get shown as R2000,00
Any help would be great.
Upvotes: 1
Views: 106
Reputation: 1627
You can you PHP's native function money_format()
, which will format the number as a currency.
Using setlocale()
you can set the appropriate locale.
setlocale(LC_MONETARY, 'en_IN');
echo money_format('%!i', 15256);
This will output:
15,256.00
Upvotes: 2
Reputation: 3302
Try This
echo number_format($order['order_total'] / 100, 2, ".", ",");
you can read more about number format here .
Upvotes: 0