note 38829 deleted from function.number-format by nlopess
| From: | nlopess@php.net | Date: | Thu, 08 Jan 2004 16:14:19 +0000 |
| Subject: | note 38829 deleted from function.number-format by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63158@lists.php.net to get a copy of this message | ||
Note Submitter: dev@maintainfit.com
----
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
*/
?>