<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Introduction</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="book.bc.html">BC Math</a></div> <div class="next" style="text-align: right; float: right;"><a href="bc.setup.html">Installing/Configuring</a></div> <div class="up"><a href="book.bc.html">BC Math</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="intro.bc" class="preface"> <h1 class="title">Introduction</h1> <p class="para"> For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision up to <em>2147483647</em> (or <em>0x7FFFFFFF</em>) decimals, if there is sufficient memory, represented as strings. </p> <div class="caution"><strong class="caution">Caution</strong> <p class="para"> Passing values of type <span class="type"><a href="language.types.float.html" class="type float">float</a></span> to a BCMath function which expects a <span class="type"><a href="language.types.string.html" class="type string">string</a></span> as operand may not have the desired effect due to the way PHP converts <span class="type"><a href="language.types.float.html" class="type float">float</a></span> values to <span class="type"><a href="language.types.string.html" class="type string">string</a></span>, namely that the <span class="type"><a href="language.types.string.html" class="type string">string</a></span> 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). </p> <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$num1 </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #FF8000">// (string) 0 => '0'<br /></span><span style="color: #0000BB">$num2 </span><span style="color: #007700">= -</span><span style="color: #0000BB">0.000005</span><span style="color: #007700">; </span><span style="color: #FF8000">// (string) -0.000005 => '-5.05E-6'<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">bcadd</span><span style="color: #007700">(</span><span style="color: #0000BB">$num1</span><span style="color: #007700">, </span><span style="color: #0000BB">$num2</span><span style="color: #007700">, </span><span style="color: #0000BB">6</span><span style="color: #007700">); </span><span style="color: #FF8000">// => '0.000000'<br /><br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_NUMERIC</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">); </span><span style="color: #FF8000">// uses a decimal comma<br /></span><span style="color: #0000BB">$num2 </span><span style="color: #007700">= </span><span style="color: #0000BB">1.2</span><span style="color: #007700">; </span><span style="color: #FF8000">// (string) 1.2 => '1,2'<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">bcsub</span><span style="color: #007700">(</span><span style="color: #0000BB">$num1</span><span style="color: #007700">, </span><span style="color: #0000BB">$num2</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">); </span><span style="color: #FF8000">// => '0.0'<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="book.bc.html">BC Math</a></div> <div class="next" style="text-align: right; float: right;"><a href="bc.setup.html">Installing/Configuring</a></div> <div class="up"><a href="book.bc.html">BC Math</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>