import transaction from firefly iii

This commit is contained in:
MaysWind
2024-10-12 01:17:56 +08:00
parent f75e078fed
commit bd66408c3d
11 changed files with 448 additions and 2 deletions
+30
View File
@@ -3,6 +3,7 @@ package utils
import (
"crypto/rand"
"math/big"
"strings"
)
// GetRandomInteger returns a random number, the max parameter represents upper limit
@@ -15,3 +16,32 @@ func GetRandomInteger(max int) (int, error) {
return int(result.Int64()), nil
}
// TrimTrailingZerosInDecimal returns a textual number without trailing zeros in decimal
func TrimTrailingZerosInDecimal(num string) string {
if len(num) < 1 {
return num
}
dotPosition := strings.Index(num, ".")
if dotPosition < 0 {
return num
}
lastNonZeroPosition := len(num)
for i := len(num) - 1; i > dotPosition+1; i-- {
if num[i] == '0' {
lastNonZeroPosition = i
} else {
break
}
}
if lastNonZeroPosition >= len(num) {
return num
}
return num[0:lastNonZeroPosition]
}