【问题标题】:PHP Round With Decimal & Comma $1,000带小数和逗号的 PHP 回合 $1,000
【发布时间】:2015-06-05 05:23:08
【问题描述】:
<?= round(number_format($vehicle->prices['total_rental'], 2, '.', ',') * 0.50,2) ?>

我希望输出四舍五入到小数点后 2 位(货币/美元和美分)。

$vehicle-&gt;pricesbelow $1,000 时,这很有效。当$vehicle-&gt;pricesabove $1,000 时,它只输出.50。四舍五入到下一个hundredth (i.e $1,452.62)的正确方法是什么?

我一直在尝试和number_format。当涉及逗号时,我似乎无法让任何一个产生正确的输出。

【问题讨论】:

    标签: php rounding number-formatting


    【解决方案1】:

    首先做一个等式,而不是四舍五入,最后使用number_format

    echo number_format(round($vehicle->prices['total_rental'] * .5, 2), 2, '.', ',');
    

    【讨论】:

    • 谢谢你,这对我很有帮助。
    猜你喜欢
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多