Go floating point problem

fmt.Println(0.1 + 0.2) // 0.3
fmt.Println(float64(0.1) + float64(0.2)) // 0.30000000000000004

what is the difference between these two floating-point calculations?

Mar.12,2021

accuracy is different, one is 32-bit, the other is 64-bit, floating-point number is approximately expressed in the computer, so the deviation is normal, it may be 32-bit error, it is possible 64-bit error, depending on which number you use. In fact, your example has nothing to do with go, and all languages will get similar results.

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-16de591-88e7.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-16de591-88e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?