go 类型转换

测试用例

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

 

上一篇:分数化小数


下一篇:python基础语法(2)