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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48657-44ccc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48657-44ccc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?