money := 100
rateStr := 7.25
row := make(map[string]interface{})
row["smoney"] = (float32(detail.Money) * 0.98) / 100.00
fmt.Println(row["smoney"], reflect.TypeOf(row["smoney"]))
smoney1, _ := row["smoney"].(float32)
rate, _ := strconv.ParseFloat(rateStr, 32)
row["count"] = smoney1 / float32(rate)
var sjsjs interface{}
sjsjs=10
sjsjs1,ok:=sjsjs.(float64)
println("sjsjsjsjs",sjsjs1,ok)
输出:
0.0000 false
注意这种转换是失败的。(从int类型的interface类型转换为float64是失败的,必须从int转化为int,如果是float64则转换为float64)
float32转float64
var a1 float32 = 23.4
a2 := float64(a1)
fmt.Printf("a1的类型是%T,a2的类型是%T", a1, a2)
输出:
a1的类型是float32,a2的类型是float64