Procházet zdrojové kódy

混合表格百分比展示

xyxie před 1 rokem
rodič
revize
2d358405f2
1 změnil soubory, kde provedl 16 přidání a 3 odebrání
  1. 16 3
      services/data/table/mixed_table.go

+ 16 - 3
services/data/table/mixed_table.go

@@ -1228,9 +1228,20 @@ func changePointDecimalPlaces(str string, changeNum int, numberType string, isPe
 	if isPercent {
 		if numberType == "number" { //百分数转成小数
 			val = val / 100
-			decimalPlaces += 2
-			if decimalPlaces > 0 {
-				decimalPlaces = 0
+			if decimalPlaces > 2 {
+				decimalPlaces += 2
+			} else if decimalPlaces == 1 {
+				decimalPlaces += 1
+			} else if decimalPlaces == 0 {
+				if len(str) == 1 {
+					decimalPlaces = 2
+				} else if len(str) == 2 {
+					if str[1] == '0' {
+						decimalPlaces = 1
+					} else {
+						decimalPlaces = 2
+					}
+				}
 			}
 			isPercent = false
 		}
@@ -1238,6 +1249,8 @@ func changePointDecimalPlaces(str string, changeNum int, numberType string, isPe
 		if numberType == "percent" {
 			if decimalPlaces > 2 {
 				decimalPlaces -= 2
+			} else if decimalPlaces == 1 {
+				decimalPlaces = 0
 			}
 			val = val * 100
 		}