CKTIS / PHP
PHP type float
A float represents a floating-point number with finite precision.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
float $ratioA float represents a floating-point number with finite precision. Decimal fractions such as one tenth may be rounded in binary, so exact equality can fail after addition. For measurements use a tolerance suited to the scale. Infinity and NAN are possible floating-point values and need explicit checks when only finite results are allowed.
$sum = 0.1 + 0.2;
echo json_encode([$sum === 0.3, abs($sum - 0.3) < 1e-12, is_finite(INF), is_nan(NAN)]);
[false,true,false,true]
Examples
<?php
$sum = 0.1 + 0.2;
echo json_encode([$sum === 0.3, abs($sum - 0.3) < 1e-12, is_finite(INF), is_nan(NAN)]);
Result
[false,true,false,true]