【发布时间】:2014-03-24 01:15:01
【问题描述】:
我正在尝试在 php 中将 2176 格式化为 21.76
我有这个代码:$Payment->amount equals 2176 in this example.
$<?php echo number_format($Payment->amount,'2')/100; ?>
我收到0.02 为什么?
【问题讨论】:
标签: php number-formatting
我正在尝试在 php 中将 2176 格式化为 21.76
我有这个代码:$Payment->amount equals 2176 in this example.
$<?php echo number_format($Payment->amount,'2')/100; ?>
我收到0.02 为什么?
【问题讨论】:
标签: php number-formatting
number_format($Payment->amount,'2') 给你字符串'2',然后你将它除以100,所以结果是0.02。
应该是:
$<?php echo number_format($Payment->amount / 100, 2); ?>
【讨论】:
您需要在格式化数字之前进行除法:
$<?php echo number_format($Payment->amount/100,'2'); ?>
【讨论】: