开发者

How to format pence as pounds and pence?

开发者 https://www.devze.com 2023-03-21 11:59 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消