代码拉取完成,页面将自动刷新
package utilGo
import "strconv"
//String 将传入的类型转为字符串
func String(val interface{}) string {
switch val.(type) {
case string:
return val.(string)
case int:
return strconv.FormatInt(int64(val.(int)), 10)
case int8:
return strconv.FormatInt(int64(val.(int8)), 10)
case int16:
return strconv.FormatInt(int64(val.(int16)), 10)
case int32:
return strconv.FormatInt(int64(val.(int32)), 10)
case int64:
return strconv.FormatInt(int64(val.(int64)), 10)
case uint:
return strconv.FormatUint(uint64(val.(uint)), 10)
case uint8:
return strconv.FormatUint(uint64(val.(uint8)), 10)
case uint16:
return strconv.FormatUint(uint64(val.(uint16)), 10)
case uint32:
return strconv.FormatUint(uint64(val.(uint32)), 10)
case uint64:
return strconv.FormatUint(uint64(val.(uint64)), 10)
case bool:
return strconv.FormatBool(val.(bool))
case float32:
return strconv.FormatFloat(val.(float64), 'f', -1, 32)
case float64:
return strconv.FormatFloat(val.(float64), 'f', -1, 64)
default:
return ""
}
}
//FormatFloat 浮点数转String 保留指定位数的小数
func FormatFloat(v interface{}, decimal int) string {
switch v.(type) {
case float32:
return strconv.FormatFloat(float64(v.(float32)), 'f', decimal, 32)
case float64:
return strconv.FormatFloat(float64(v.(float64)), 'f', decimal, 64)
default:
return ""
}
}
//FormatInt 整数转字符串
func FormatInt(val interface{}) string {
switch val.(type) {
case int:
return strconv.FormatInt(int64(val.(int)), 10)
case int8:
return strconv.FormatInt(int64(val.(int8)), 10)
case int16:
return strconv.FormatInt(int64(val.(int16)), 10)
case int32:
return strconv.FormatInt(int64(val.(int32)), 10)
case int64:
return strconv.FormatInt(int64(val.(int64)), 10)
case uint:
return strconv.FormatUint(uint64(val.(uint)), 10)
case uint8:
return strconv.FormatUint(uint64(val.(uint8)), 10)
case uint16:
return strconv.FormatUint(uint64(val.(uint16)), 10)
case uint32:
return strconv.FormatUint(uint64(val.(uint32)), 10)
case uint64:
return strconv.FormatUint(uint64(val.(uint64)), 10)
default:
return ""
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。