How can I avoid floating point errors when converting float's to int's.
For example the following code prints: 0.5499999999999972
when I wound expect it to print 0.55
.
package main
import "fmt"
func main() {
x := 100.55
fmt.Println(x - float64(int(x)))
}
Output:
0.5499999999999972
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…