提交 0be69bbc 编写于 作者: N ning

feat: add FormatDecimal

上级 7015a402
......@@ -352,3 +352,13 @@ func Divide(a, b interface{}) (interface{}, error) {
return nil, fmt.Errorf("divide: unknown type for %q (%T)", av, a)
}
}
func FormatDecimal(s string, n int) string {
num, err := strconv.ParseFloat(s, 64)
if err != nil {
return s
}
format := fmt.Sprintf("%%.%df", n)
return fmt.Sprintf(format, num)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册