Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #21769 [Form] Improve rounding precision (foaly-nr1)
This PR was squashed before being merged into the 2.7 branch (closes #21769). Discussion ---------- [Form] Improve rounding precision | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | 21734 | License | MIT | Doc PR | For full details see #21734 from #21734 (comment) onwards. Excerpt: ```php $number = floor(37.37*100); // double(3736) var_dump($number); $number = floor(bcmul(37.37, 100)); // double(3737) var_dump($number); ``` From http://php.net/manual/en/language.types.float.php#language.types.float: > Additionally, rational numbers that are exactly representable as floating point numbers in base 10, like 0.1 or 0.7, do not have an exact representation as floating point numbers in base 2, which is used internally, no matter the size of the mantissa. Hence, they cannot be converted into their internal binary counterparts without a small loss of precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8, since the internal representation will be something like 7.9999999999999991118.... > > So never trust floating number results to the last digit, and do not compare floating point numbers directly for equality. If higher precision is necessary, the arbitrary precision math functions and gmp functions are available. Commits ------- e50804c [Form] Improve rounding precision
- Loading branch information