mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
build/ci: Update Go to v1.24, golangci-lint to v1.64.6 and fix issues (#1804)
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues * Address shazbert's nitters * linter/config: Fix new linter issue and use versionSize const * Address gk's nitters and fix additional linter issue after rebase * Address glorious nits * staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6 Also addresses nits * Improve testing, assertify usage and use common.ErrParsingWSField * TestCreateNewStrategy: Replace must > should wording
This commit is contained in:
@@ -103,14 +103,13 @@ func FloatToHumanFriendlyString(number float64, decimals uint, decPoint, thousan
|
||||
number = -number
|
||||
neg = true
|
||||
}
|
||||
dec := int(decimals)
|
||||
str := fmt.Sprintf("%."+strconv.Itoa(dec)+"F", number)
|
||||
return numberToHumanFriendlyString(str, dec, decPoint, thousandsSep, neg)
|
||||
str := fmt.Sprintf("%."+strconv.FormatUint(uint64(decimals), 10)+"F", number)
|
||||
return numberToHumanFriendlyString(str, decimals, decPoint, thousandsSep, neg)
|
||||
}
|
||||
|
||||
// DecimalToHumanFriendlyString converts a decimal number to a comma separated string at the thousand point
|
||||
// eg 1000 becomes 1,000
|
||||
func DecimalToHumanFriendlyString(number decimal.Decimal, rounding int, decPoint, thousandsSep string) string {
|
||||
func DecimalToHumanFriendlyString(number decimal.Decimal, rounding uint, decPoint, thousandsSep string) string {
|
||||
neg := false
|
||||
if number.LessThan(decimal.Zero) {
|
||||
number = number.Abs()
|
||||
@@ -119,20 +118,25 @@ func DecimalToHumanFriendlyString(number decimal.Decimal, rounding int, decPoint
|
||||
str := number.String()
|
||||
if rnd := strings.Split(str, "."); len(rnd) == 1 {
|
||||
rounding = 0
|
||||
} else if len(rnd[1]) < rounding {
|
||||
rounding = len(rnd[1])
|
||||
} else if uint(len(rnd[1])) < rounding {
|
||||
rounding = uint(len(rnd[1]))
|
||||
}
|
||||
return numberToHumanFriendlyString(number.StringFixed(int32(rounding)), rounding, decPoint, thousandsSep, neg)
|
||||
|
||||
if rounding > math.MaxInt32 {
|
||||
rounding = math.MaxInt32 // Not feasible to test due to the size of the number
|
||||
}
|
||||
|
||||
return numberToHumanFriendlyString(number.StringFixed(int32(rounding)), rounding, decPoint, thousandsSep, neg) //nolint:gosec // Checked above
|
||||
}
|
||||
|
||||
func numberToHumanFriendlyString(str string, dec int, decPoint, thousandsSep string, neg bool) string {
|
||||
func numberToHumanFriendlyString(str string, dec uint, decPoint, thousandsSep string, neg bool) string {
|
||||
var prefix, suffix string
|
||||
if len(str)-(dec+1) < 0 {
|
||||
if dec > 0 && (dec)+1 > uint(len(str)) {
|
||||
dec = 0
|
||||
}
|
||||
if dec > 0 {
|
||||
prefix = str[:len(str)-(dec+1)]
|
||||
suffix = str[len(str)-dec:]
|
||||
prefix = str[:len(str)-(int(dec)+1)]
|
||||
suffix = str[len(str)-int(dec):]
|
||||
} else {
|
||||
prefix = str
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user