mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
5b848aeb03
commit
b5397d3cda
1 changed files with 25 additions and 0 deletions
|
@ -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>
|
||||
<!-- }}} -->
|
||||
|
||||
|
|
Loading…
Reference in a new issue