note 51515 added to function.number-format
| From: | mike at phpeeb dot com | Date: | Sat, 02 Apr 2005 09:13:10 +0000 |
| Subject: | note 51515 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87338@lists.php.net to get a copy of this message | ||
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 */
?>
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51515
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51515&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51515&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51515&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51515&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51515&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51515&report=yes
Search -- http://master.php.net/manage/user-notes.php