I am attempting 开发者_如何学Goto 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?
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
Divide it by 100?
1345 / 100 = 13.45
Look at this MySQL math function reference.
How about
Select format(amt/100.0,'#,###,###.##') from mytable
精彩评论