Browse Source

Merge branch 'feature/fix_excel_decimal' of eta_server/eta_api into debug

baoziqiang 5 months ago
parent
commit
e8d887c2b4
1 changed files with 11 additions and 3 deletions
  1. 11 3
      services/data/excel/mixed_table.go

+ 11 - 3
services/data/excel/mixed_table.go

@@ -1276,6 +1276,14 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 					styleConf.Pn = 0
 				} else if styleConf.Decimal != nil {
 					cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
+				} else {
+					if hasPercent {
+						numDecimal, _ := decimal.NewFromString(cell.ShowValue)
+						tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
+						cell.ShowFormatValue = tmpStr + "%"
+					} else {
+						cell.ShowFormatValue = cell.ShowValue
+					}
 				}
 			} else if styleConf.Decimal != nil {
 				cell.ShowFormatValue = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
@@ -1308,11 +1316,11 @@ func getDecimalLen(str string, isPercent bool) (decimalPlaces int) {
 }
 
 func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
-	numFloat, _ := strconv.ParseFloat(num, 64)
+	numDecimal, _ := decimal.NewFromString(num)
 	if hasPercent {
-		numFloat = numFloat * 100
+		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
 	}
-	numFloat, _ = decimal.NewFromFloat(numFloat).Round(int32(decimalPlaces)).Float64()
+	numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
 	numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
 	if hasPercent {
 		numStr += "%"