Trouble using strconv.FormatFloat() in type switch
go
Solution
The first argument to `FormatFloat` needs to be a float64, and you are passing a float32. The easiest way to fix this is to simply cast the 32bit float to a 64bit float.
case float32:
return strconv.FormatFloat(float64(val), 'f', -1, 32)
http://play.golang.org/p/jBPaQ-jMBT
Problem
I'm simply trying to use a type switch for handling times, float32s and float64s. It's working fine for times and float64s, but `strconv.FormatFloat(val, 'f', -1, 32)` keeps telling me that I can't use `type float32` as `type float64`. I don't see how that could be happening, so I must be missing something or misunderstanding how I'm supposed to be calling `FormatFloat()` for `float32s`. ``` func main() { fmt.Println(test(rand.Float32())) fmt.Println(test(rand.Float64())) } func test(val interface{}) string { switch val := val.(type) { case time.Time: return fmt.Sprintf("%s", val) case float64: return strconv.FormatFloat(val, 'f', -1, 64) case float32: return strconv.FormatFloat(val, 'f', -1, 32) //here's the error default: return "Type not supported!" } } ``` Error: cannot use val (type float32) as type float64 in argument to strconv.FormatFloat