Reputation: 5747
I am attempting to read out a value from the database in pence.
For example, if I read out 1345 pence, this is £13.45.
What is the best way to ALWAYS put a dot after the first 2 decimal places?
Upvotes: 3
Views: 4356
Reputation: 1118
You need to watch out for numbers ending in 0. Dividing by 100 will remove them in your final price.
EG: 1290/100 will return 12.9.
Try using number_format
number_format($price/100, 2);
$price = 1345;
//returns 13.45
$price = 1200
//returns 12.00
$price = 1290
//returns 12.90
Upvotes: 7
Reputation: 12339
Look at this MySQL math function reference.
How about
Select format(amt/100.0,'#,###,###.##') from mytable
Upvotes: 0