I would use number_format: http://php.net/number_format
if you var_dump() your constant, you see its internal representation is a double, it is only a manner of how you show it.
题
I'm building a web application that is handling some money/prices that may change from time to time. To facilitate this, I have a config.php
which is required and includes some definitions:
define('PRODUCT_PRICE', 2000.00);
define('PRODUCT_PRICE_WITH_GST', PRODUCT_PRICE * 1.1);
When it comes time for the prospect to enter the checkout process, I display the price as follows:
<?php echo(PRODUCT_PRICE_WITH_GST); ?>
I was expecting this to print as 2200.00
but rather it's dropping off the decimal points and displaying as 2200
.
What's the best practice way to handle this?
解决方案
I would use number_format: http://php.net/number_format
if you var_dump() your constant, you see its internal representation is a double, it is only a manner of how you show it.