init: 1.0.0

This commit is contained in:
Chang lue Tsen
2025-04-25 12:08:29 +09:00
commit 8addcc584b
1031 changed files with 76472 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package tool
import (
"math"
"strconv"
)
func FormatFloat(num float64, decimal int) string {
// 默认乘1
d := float64(1)
if decimal > 0 {
// 10的N次方
d = math.Pow10(decimal)
}
// math.trunc作用就是返回浮点数的整数部分
// 再除回去,小数点后无效的0也就不存在了
return strconv.FormatFloat(math.Trunc(num*d)/d, 'f', -1, 64)
}
func FormatStringToFloat(str string) float64 {
value, err := strconv.ParseFloat(str, 64)
if err != nil {
return 0
}
return value
}