note 40686 deleted from ref.bc by nlopess

From: Date: Thu, 11 Mar 2004 14:57:08 +0000
Subject: note 40686 deleted from ref.bc by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-66653@lists.php.net to get a copy of this message
Note Submitter: george@whiffen.net ---- More exponential gotchas: Even if you think your number is not in exponential notation, php may change it to exponential before passing it to bc e.g. bcadd(100000000000000,1) returns 1 bcadd(0.00001,0.00001,5) returns 0 The first example can be solved by increasing the value of php's precision configuration variable, e.g. ini_set('precision',20). This does not work for the second example, which requires you to do the string conversion yourself using the "f" type of sprintf() e.g. bcadd(sprintf("%.5f",0.00001),sprintf("%.5f",0.00001),5) However, be aware that the "f" type of printf/sprintf is limited as to number of places i.e. this won't work for 1e-40. It's probably best to avoid using numbers with bc altogether and just keep everything as string e.g. bcadd('0.00001','0.00001',5). It's faster as well as safer.

« previous php.notes (#66653) next »