foroco / php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing
MIT License
126 stars 34 forks source link

Using Float datatype for version causes inaccuracy #29

Open marzvrover opened 5 months ago

marzvrover commented 5 months ago

It is inaccurate to use a float for versions. 17.10 is not the same as 17.1, but by using casting as a float they both appear as 17.1.

foroco commented 2 weeks ago

The issue is quite complicated.

This behavior is related to the way PHP handle floats.

PHP uses binary representation for floating point numbers (typically IEEE 754 format). In this format, some decimal fractions cannot be represented accurately. PHP automatically trims insignificant zeros after the decimal point. Thus, 17.10 becomes 17.1. When using functions like floatval(), PHP does not preserve information about the number of decimal places.

I need to figure out the best way to solve the issue.