2 Star 0 Fork 0

big_meteor / lsp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Zero Two 提交于 2021-10-20 19:21 . utils update
package utils
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
func Strval(value interface{}) string {
var key string
if value == nil {
return key
}
switch value.(type) {
case float64:
ft := value.(float64)
key = strconv.FormatFloat(ft, 'f', -1, 64)
case float32:
ft := value.(float32)
key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
case int:
it := value.(int)
key = strconv.Itoa(it)
case uint:
it := value.(uint)
key = strconv.Itoa(int(it))
case int8:
it := value.(int8)
key = strconv.Itoa(int(it))
case uint8:
it := value.(uint8)
key = strconv.Itoa(int(it))
case int16:
it := value.(int16)
key = strconv.Itoa(int(it))
case uint16:
it := value.(uint16)
key = strconv.Itoa(int(it))
case int32:
it := value.(int32)
key = strconv.Itoa(int(it))
case uint32:
it := value.(uint32)
key = strconv.Itoa(int(it))
case int64:
it := value.(int64)
key = strconv.FormatInt(it, 10)
case uint64:
it := value.(uint64)
key = strconv.FormatUint(it, 10)
case string:
key = value.(string)
case []byte:
key = string(value.([]byte))
default:
newValue, _ := json.Marshal(value)
key = string(newValue)
}
return key
}
func DecimalPlaces(value float64) int64 {
numStr := fmt.Sprint(value)
tmp := strings.Split(numStr, ".")
if len(tmp) <= 1 {
return 0
}
return int64(len(tmp[1]))
}
Go
1
https://gitee.com/big_meteor/lsp.git
git@gitee.com:big_meteor/lsp.git
big_meteor
lsp
lsp
a2fcaf7203d3

搜索帮助

53164aa7 5694891 3bd8fe86 5694891