duanqiaoren9975 2011-05-08 20:10
浏览 44

如何将PHP中的价格相乘并将零保持在最后?

I'm building a simple e-commerse site in php. In the cart where the product prices are added, I simply multiply them ie. $totalPrice=$price * $qty, but, any zero's at the end get chopped off. It's ok if the total price of items is, say.. $10.52, but any zero's don't display after they've been muliplied.

Here is the url to my site www.allthingsskin.com.au

If you add an item to the cart you'll see what I'm trying to explain.

Any help is GREATLY appreciated.

Thanks

Mark

  • 写回答

1条回答 默认 最新

  • duanbipu7601 2011-05-08 20:11
    关注

    number_format is the function you are looking for. The first parameter is your total, the 2nd parameter is the number of decimal places.

    echo number_format(10, 2); // returns 10.00
    

    You can also use money_format.

    评论

报告相同问题?