저는 times, float32s 및 float64s를 처리하기 위해 타입 스위치를 사용하려고합니다. 시간과 float64에 대해서는 문제없이 작동하지만 strconv.FormatFloat(val, 'f', -1, 32)
은 type float32
을 type float64
으로 사용할 수 없다고 계속 말합니다. 그 일이 어떻게 될지 모르겠다. 그래서 무언가를 놓치거나 내가 어떻게 부름을해야하는지 오해해야한다. FormatFloat()
float32s
.타입 스위치에 strconv.FormatFloat()를 사용하는 데 문제가 있습니다
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!"
}
}
오류 :
는cannot use val (type float32) as type float64 in argument to strconv.FormatFloat