mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-26 21:59:37 +08:00
26
kit/utils/float_to_f.go
Normal file
26
kit/utils/float_to_f.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ParseFloat2F(value float64) float64 {
|
||||
newValue, err := strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
|
||||
if err != nil {
|
||||
fmt.Println("保留2位小数, 转换float出错")
|
||||
return value
|
||||
}
|
||||
return newValue
|
||||
|
||||
}
|
||||
|
||||
func ParseStringToInt64(value string) int64 {
|
||||
|
||||
newValue, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("string转换int64出错")
|
||||
return 0
|
||||
}
|
||||
return newValue
|
||||
}
|
||||
Reference in New Issue
Block a user