Ver Fonte

fix:修复百分比计算的bug

Roc há 10 meses atrás
pai
commit
dd3c8e50a6
2 ficheiros alterados com 2 adições e 4 exclusões
  1. 0 1
      go.mod
  2. 2 3
      utils/common.go

+ 0 - 1
go.mod

@@ -113,7 +113,6 @@ require (
 	github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
 	golang.org/x/crypto v0.19.0 // indirect
 	golang.org/x/image v0.15.0 // indirect
-	golang.org/x/net v0.21.0 // indirect
 	golang.org/x/sys v0.17.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
 	golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect

+ 2 - 3
utils/common.go

@@ -2183,14 +2183,13 @@ func DealDateTimeZero(t time.Time, format string) (timeStr string) {
 // @return bool
 // @return string
 func IsPercentage(input string) (bool, string) {
-	percentagePattern := `^(\d{1,2}(\.\d{1,2})?)%$`
+	percentagePattern := `^-?(\d{1,2}(\.\d{1,2})?)%$`
 	match, _ := regexp.MatchString(percentagePattern, input)
 
 	if match {
-		// 提取百分比值
 		re := regexp.MustCompile(percentagePattern)
 		match := re.FindStringSubmatch(input)
-		return true, match[1]
+		return true, match[1] // 返回第一个捕获组的内容,即整个负数百分比数值
 	}
 
 	return false, ""