1 Star 0 Fork 0

tomatomeatman / GolangRepository

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
FloatUtil.go 765 Bytes
一键复制 编辑 原始数据 按行查看 历史
tomatomeatman 提交于 2023-06-04 18:07 . no commit message
package data
import (
"fmt"
"strconv"
"unsafe"
)
type FloatUtil struct{}
//对象(字符串)转浮点数
func (this FloatUtil) ToStr(obj float64) string {
return fmt.Sprintf("%f", obj)
}
//对象(字符串)转64整型
func (this FloatUtil) ToFloat(obj interface{}, bitSize int, iDefault float64) float64 {
var str string
switch obj.(type) {
case []uint8:
str = this.Byte2Str(obj.([]uint8))
default:
str = fmt.Sprintf("%v", obj)
}
if str == "" { //字符串不能判断nil
return iDefault
}
result, err := strconv.ParseFloat(str, bitSize)
if err != nil {
return iDefault
}
return result
}
// Byte转Str
func (this FloatUtil) Byte2Str(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
Go
1
https://gitee.com/tomatomeatman/golang-repository.git
git@gitee.com:tomatomeatman/golang-repository.git
tomatomeatman
golang-repository
GolangRepository
bcb142e03580

搜索帮助

53164aa7 5694891 3bd8fe86 5694891