diff --git a/float_util.go b/float_util.go index c6e5be4..999a59b 100644 --- a/float_util.go +++ b/float_util.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "math/big" + "strings" ) func RoundFloat64(f float64, dec int) float64 { @@ -64,3 +65,20 @@ func Float64PtrToString(f *float64) string { } return fmt.Sprintf("%.2f", *f) } + +func FormatFloat64Number(f float64, dec int) string { + res := "" + + f = RoundFloat64(f, dec) + + i := int64(f) + + format := fmt.Sprintf("%%.%df", dec) + parts := strings.Split(fmt.Sprintf(format, f-float64(i)), ".") + + decimals := parts[1] + + res = FormatInt64Number(i) + "," + decimals + + return res +} diff --git a/int_util.go b/int_util.go index 3c2146c..9c4e41f 100644 --- a/int_util.go +++ b/int_util.go @@ -65,3 +65,15 @@ func MinInt64(vars ...int64) (min int64) { } return min } + +func FormatInt64Number(i int64) string { + res := "" + + for i >= 1000 { + rem := i % 1000 + i = i / 1000 + res = res + fmt.Sprintf(".%03d", rem) + } + res = fmt.Sprintf("%d", i) + res + return res +}