donglizhan7848 2014-03-24 01:15
浏览 78
已采纳

在PHP中正确格式化数字

I am trying to format 2176 as 21.76 in php

I have this code: $Payment->amount equals 2176 in this example.

$<?php echo number_format($Payment->amount,'2')/100; ?>

I get 0.02 Why?

  • 写回答

2条回答 默认 最新

  • doukuizuo1795 2014-03-24 01:16
    关注

    number_format($Payment->amount,'2') gives you string '2', then you divide it by 100, so the result is 0.02.

    It should be:

    $<?php echo number_format($Payment->amount / 100, 2); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?