34 lines
564 B
Go
34 lines
564 B
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
// StrToFloat32 字符串转float32
|
|
func StrToFloat32(s string) (f *float32, err error) {
|
|
f64, err := strconv.ParseFloat(s, 32)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 将float64转换为float32
|
|
f32 := float32(f64)
|
|
|
|
return &f32, nil
|
|
}
|
|
|
|
// StrToFloat64 字符串转float64
|
|
func StrToFloat64(s string) (f *float64, err error) {
|
|
f64, err := strconv.ParseFloat(s, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &f64, nil
|
|
}
|
|
|
|
// IntToBool 将整数转换为布尔值
|
|
func IntToBool(value int) bool {
|
|
return value != 0
|
|
}
|