A strange problem of converting PHP floating-point numbers to integers

<?php
$a = round(96800 / 365, 2) * 1000 / 10;
var_dump($a);
$a = intval($a);
var_dump($a);

$b = round(96800 / 365, 2) * 100;
var_dump($b);
$b = intval($b);
var_dump($b);

calculation result:

float(26521)
int(26521)
float(26521)
int(26520)
Php
Mar.03,2021

it's not surprising that this happens all the time.

float a = 0.999999999 , an is 1, but when an is cast to an integer, the result is 0. Mainly truncate

when turning integers.

floating-point numbers are all approximately equal, and their precision depends on the multiple of expansion. For example, 1-3-4; but 0.1-0.2 is not equal to 0.3

Menu