note 38829 added to function.number-format
| From: | dev at maintainfit dot com | Date: | Thu, 08 Jan 2004 03:05:03 +0000 |
| Subject: | note 38829 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63124@lists.php.net to get a copy of this message | ||
I was trying to find the negative value of a formatted float, but going about it the wrong way. The
following script illustrates what I was doing wrong,
<?
$float_value = -1231.3448852; //note that this float will have a comma added by number_format
echo $float_value."<br>\n";
echo number_format($float_value,2)."<br>\n"; //this is fine
echo -number_format($float_value,2)."<br>\n"; //here's the error
echo number_format(-$float_value,2)."<br>\n"; //this is fine
/*
output:
-1231.3448852
-1,231.34
1
1,231.34
*/
$float_value = -131.3448852; //note that this float will NOT have a comma added by number_format
echo $float_value."<br>\n";
echo number_format($float_value,2)."<br>\n"; //this is fine
echo -number_format($float_value,2)."<br>\n"; //this works because number_format
does not place a comma in the returned number
echo number_format(-$float_value,2)."<br>\n"; //this is fine
/*
output:
-131.3448852
-131.34
131.34
131.34
*/
?>
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38829
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38829&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38829&report=yes
Search -- http://master.php.net/manage/user-notes.php