When printing some values ββfrom a structure map. I see some float64 values ββwith alternative notation. The test passes, but as you read this notation (4e-06). Is this value really the same as "0.000004"?
package main import ( "fmt" "strconv" "testing" ) func TestXxx(t *testing.T) { num := fmt.Sprintf("%f", float64(1.225788)-float64(1.225784)) // 0.000004 f, _ := strconv.ParseFloat(num, 64) if f == 0.000004 { t.Log("Success") } else { t.Error("Not Equal", num) } if getFloat(f) == 0.000004 { t.Log("Success") }else{ t.Error("Fail", getFloat(f)) } } func getFloat(f float64) float64 { fmt.Println("My Float:",f) // 4e-06 return f }
source share