我试图在 php 中将 2176
格式化为 21.76
我有这段代码:$Payment->本例中的金额等于 2176。
$<?php echo number_format($Payment->amount,'2')/100; ?>
我得到 0.02
为什么?
最佳答案
number_format($Payment->amount,'2')
给你字符串 '2'
,然后你将它除以 100
,所以结果是 0.02
。
应该是:
$<?php echo number_format($Payment->amount / 100, 2); ?>
关于php - 在 php 中正确格式化数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22599491/