开发者

How do I multiply a price in PHP and keep the zeroes at the end?

开发者 https://www.devze.com 2023-03-04 16:52 出处:网络
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

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 ite开发者_如何学JAVAm to the cart you'll see what I'm trying to explain.

Any help is GREATLY appreciated.

Thanks

Mark


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消