Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

precision

Precision refers to the number of digits are used to represent and display floating-point numbers. The exact meaning depends a bit on the context, but it’s most commonly about float accuracy and formatting.

Precision is important when using a decimal number as an array index: the conversion is implicit, and, nowadays, it yields a warning.

Precision is also lost when an integer is converted to a decimal number, which may not be accurately represented. This happens with large integers, when they are converted to float, because of their size.

precision and serialize_precision are two PHP directives, that controls the display or conversion of numbers.

<<?php

    echo 1 / 7;
    
    print PHP_EOL;
    
    ini_set('precision', 2);
    
    echo 1 / 7;

?>

Documentation