Skip to content

Commit e48e3f4

Browse files
authored
Merge pull request #151 from kaytu-io/fix-approved-plugins
fix: fix FormatFloat function
2 parents d11f4e1 + f95ad66 commit e48e3f4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: pkg/utils/view.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"fmt"
5+
"math"
56
"strings"
67
)
78

@@ -81,6 +82,11 @@ func SizeByteToGB(v *int32) string {
8182
}
8283

8384
func FormatFloat(number float64) string {
85+
isNegative := false
86+
if number < 0 {
87+
isNegative = true
88+
number = math.Abs(number)
89+
}
8490
parts := strings.Split(fmt.Sprintf("%.2f", number), ".")
8591
integerPart := parts[0]
8692
decimalPart := parts[1]
@@ -92,6 +98,9 @@ func FormatFloat(number float64) string {
9298
}
9399
result = append(result, rune(digit))
94100
}
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+
}
97106
}

0 commit comments

Comments
 (0)