note 69500 added to ref.bc
| From: | jrf at NOSPAM dot jokeaday dot net | Date: | Thu, 07 Sep 2006 23:12:44 +0000 |
| Subject: | note 69500 added to ref.bc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116880@lists.php.net to get a copy of this message | ||
BEWARE !
The bcmath functions do not abide by the normal rounding rules, but 'cut off' your string
at the digit specified by precision.
<?php
$x = '0.00016132';
print bcadd( $x, 0, 4 ); // add 0 to try and round off the number at 4 digits
printf( '%01.4f', round( $x, 4 ) ); // this does work
printf( '%01.4f', $x ); // this works too - round() is not needed as (s)printf will round
automatically
?>
results in:
0.0001 // incorrect
0.0002 // correct
0.0002 // correct
----
Server IP: 83.137.20.120
Probable Submitter: 62.234.167.227
----
Manual Page -- http://www.php.net/manual/en/ref.bc.php
Edit -- https://master.php.net/note/edit/69500
Del: integrated -- https://master.php.net/note/delete/69500/integrated
Del: useless -- https://master.php.net/note/delete/69500/useless
Del: bad code -- https://master.php.net/note/delete/69500/bad+code
Del: spam -- https://master.php.net/note/delete/69500/spam
Del: non-english -- https://master.php.net/note/delete/69500/non-english
Del: in docs -- https://master.php.net/note/delete/69500/in+docs
Del: other reasons-- https://master.php.net/note/delete/69500
Reject -- https://master.php.net/note/reject/69500
Search -- https://master.php.net/manage/user-notes.php