Fix bug #66745: Scientific notation

We document that float to string is problematic for BCMath.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@343020 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christoph Michael Becker 2017-09-07 22:23:27 +00:00
parent 5b848aeb03
commit b5397d3cda

View file

@ -13,6 +13,31 @@
For arbitrary precision mathematics PHP offers the Binary Calculator which
supports numbers of any size and precision up to 2147483647-1 (or 0x7FFFFFFF-1) decimals, represented as strings.
</para>
<caution>
<para>
Passing values of type <type>float</type> to a BCMath function which expects
a <type>string</type> as operand may not have the desired effect due to the
way PHP converts <type>float</type> values to <type>string</type>, namely
that the <type>string</type> may be in exponential notation (what is not
supported by BCMath), and that the decimal separator is locale dependend
(while BCMath always expects a decimal point).
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$num1 = 0; // (string) 0 => '0'
$num2 = -0.000005; // (string) -0.000005 => '-5.05E-6'
echo bcadd($num1, $num2, 6); // => '0.000000'
setlocale(LC_NUMERIC, 'de_DE'); // uses a decimal comma
$num2 = 1.2; // (string) 1.2 => '1,2'
echo bcsub($num1, $num2, 1); // => '0.0'
?>
]]>
</programlisting>
</informalexample>
</caution>
</preface>
<!-- }}} -->