Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>According to the docs, the <a href="http://www.php.net/manual/en/ini.core.php#ini.precision" rel="nofollow">precision directive</a> just changes the digits shown when casting numbers to strings:</p> <blockquote> <p><strong>precision</strong> <code>integer</code><br> The number of significant digits displayed in floating point numbers. </p> </blockquote> <p>So it's basically a very convoluted alternative to <a href="http://php.net/number_format" rel="nofollow">number_format()</a> or <a href="http://php.net/money_format" rel="nofollow">money_format()</a>, except that it has less formatting options and it can suffer from some other side effects you might not be aware:</p> <pre><code>&lt;?php $_POST['amount'] = '1234567.89'; $amount = floatval($_POST['amount']); var_dump($amount); ini_set('precision', 5); $amount = floatval($_POST['amount']); var_dump($amount); </code></pre> <p>...</p> <pre><code>float(1234567.89) float(1.2346E+6) </code></pre> <p><strong>Edit:</strong></p> <p>I insist: this setting does not alter the way PHP makes mathematical calculations with numbers. It's just a magical way to change format options when <em>converting</em> from floating point numbers (not even integers!) to strings. Example:</p> <pre><code>&lt;?php ini_set('precision', 2); $amount = 1000; $price = 98.76; $total = $amount*$price; var_dump($amount, $total); ini_set('precision', 15); var_dump($amount, $total); </code></pre> <p>... prints:</p> <pre><code>int(1000) float(9.9E+4) int(1000) float(98760) </code></pre> <p>Which illustrates that:</p> <ol> <li>Floating point calculations are unaffected, only the <em>display</em> changes</li> <li>Integers are unaffected in all cases</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload