SQLite Forum

ORDER BY not working for a specific DB/table
Login
The nearest schoolboy rounding of 30.1233198123987303101203 to 1 decimal place is 30.1, which has the nearest representable value 30.10000000000000142.  

The nearest representable value of 30.1 is also 30.10000000000000142.

sqlite> select round(30.1233198123987303101203,1) == 30.1;  
1

Similarly for the schoolboy rounding of 30.817232123312 to 0 decimal places is 31.0, and the nearest representable value of 31.0 is 30.999999999999999999.

sqlite> select round(30.817232123312) == 31;  
1  
sqlite> select round(30.817232123312) == 31.0;  
1

Just because the exact rounded representation is not music to your eyes does not mean it is incorrect.  The error in the result is less than 0.5 ULP as required by the IEEE specification.

<https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html> for a technical explanation of **What Every Computer Scientist Should Know About Floating-Point Arithmetic** and why IEEE base-2 floating point works as it does.