note 61647 added to function.bcscale
| From: | invincible at limitedintelligence dot com | Date: | Wed, 08 Feb 2006 11:50:47 +0000 |
| Subject: | note 61647 added to function.bcscale | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103304@lists.php.net to get a copy of this message | ||
If you don't set the default scale, be careful when you're chaining together several BC
math functions - since by default, these functions will round off your values, losing accuracy very
quickly:
<?php
$a = 1.234
$b = 2.345
$c = 7.890
$ab = bcmul($a,$b); // 2
$abc = bcmul($ab,$c);
echo $abc; // 15
?>
... compare with the answer you get when you use more decimal places:
<?php
$a = 1.234
$b = 2.345
$c = 7.890
bcscale(15);
$ab = bcmul($a,$b); // 2.893730
$abc = bcmul($ab,$c);
echo $abc; // 22.83152970
?>
----
Server IP: 203.202.10.60
Probable Submitter: 220.239.121.53
----
Manual Page -- http://www.php.net/manual/en/function.bcscale.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61647
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61647&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61647&report=yes
Search -- http://master.php.net/manage/user-notes.php