From e25e0091a873e6bbe3d55eb7de5d0152fb120363 Mon Sep 17 00:00:00 2001 From: dulanting Date: Mon, 13 Oct 2025 15:36:32 +0800 Subject: [PATCH] refactor: use strings.Builder to improve performance Signed-off-by: dulanting --- numbers/decimal.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/numbers/decimal.go b/numbers/decimal.go index 05e63c3..105c2ce 100644 --- a/numbers/decimal.go +++ b/numbers/decimal.go @@ -52,11 +52,11 @@ func DecimalExp(dec string, exp int) string { i -= origSize - len(dec) // Fix bounds if i <= 0 { - zeros := "" + var zeros strings.Builder for ; i < 0; i++ { - zeros += "0" + zeros.WriteString("0") } - return "0." + zeros + dec + return "0." + zeros.String() + dec } else if i >= len(dec) { for i > len(dec) { dec += "0" @@ -82,8 +82,8 @@ func HexToDecimal(hex string) (string, error) { // CutZeroFractional cuts off a decimal separator and zeros to the right. // Fails if the fractional part contains contains other digits than zeros. -// - CutZeroFractional("123.00000") => ("123", true) -// - CutZeroFractional("123.456") => ("", false) +// - CutZeroFractional("123.00000") => ("123", true) +// - CutZeroFractional("123.456") => ("", false) func CutZeroFractional(dec string) (integer string, ok bool) { // Get comma position comma := strings.IndexRune(dec, '.')