go 类型转换
作者:互联网
测试用例
package code import ( "github.com/shopspring/decimal" ) //float64转成int64 func Float64ToInt64(s interface{}) int64 { var data int64 if s != nil { s1, ok := s.(float64) if ok { data = decimal.NewFromFloat(s1).IntPart() } } return data } //string转成int64 func StringToInt64(s interface{}) int64 { var data int64 if s != nil { s1, ok := s.(string) if ok { fromString, _ := decimal.NewFromString(s1) data = fromString.IntPart() } } return data }View Code
标签:类型转换,ok,fromString,s1,int64,go,data,decimal 来源: https://www.cnblogs.com/huay/p/14984708.html