File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package utils
2
2
3
3
import (
4
4
"fmt"
5
+ "math"
5
6
"strings"
6
7
)
7
8
@@ -81,6 +82,11 @@ func SizeByteToGB(v *int32) string {
81
82
}
82
83
83
84
func FormatFloat (number float64 ) string {
85
+ isNegative := false
86
+ if number < 0 {
87
+ isNegative = true
88
+ number = math .Abs (number )
89
+ }
84
90
parts := strings .Split (fmt .Sprintf ("%.2f" , number ), "." )
85
91
integerPart := parts [0 ]
86
92
decimalPart := parts [1 ]
@@ -92,6 +98,9 @@ func FormatFloat(number float64) string {
92
98
}
93
99
result = append (result , rune (digit ))
94
100
}
95
-
96
- return fmt .Sprintf ("%s.%s" , string (result ), decimalPart )
101
+ if isNegative {
102
+ return fmt .Sprintf ("-%s.%s" , string (result ), decimalPart )
103
+ } else {
104
+ return fmt .Sprintf ("%s.%s" , string (result ), decimalPart )
105
+ }
97
106
}
You can’t perform that action at this time.
0 commit comments