This question already has an answer here:
- Is floating point math broken? 30 answers
How does the float arithmetic work in Go
Playground link
package main
import "fmt"
func main() {
j := 1.021
fmt.Println(j)
k := j*1000
fmt.Println(k)
l := int(k)
fmt.Println(l)
}
Output:
1.021
1020.9999999999999
1020
I was expecting 1021
to be printed, but I got 1020
</div>