note 51515 deleted from function.number-format by cmb

From: Date: Sun, 08 Sep 2019 10:17:33 +0000
Subject: note 51515 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212126@lists.php.net to get a copy of this message
Note Submitter: mike at phpeeb dot com ---- Since number_format returns a string, you must perform all mathmatical functions on the number before applying number_format: <? $total = 100; $total = number_format($total, 2); $shipping = 20.00; $grand_total = $total + $shipping; echo number_format($grand_total, 2); /* The above will return 21.00 because $total is now a string, and no longer an integer or float. Since a string will have a value of 1, the addition of the two will return 21 and not 120. */ $total = 100; $shipping = 20.00; $grand_total = $total + $shipping; echo number_format($grand_total, 2); /* This works, and will return 120.00 as intended */ ?>

« previous php.notes (#212126) next »