Przeglądaj źródła

fix:小数点位数显示

zqbao 5 miesięcy temu
rodzic
commit
2d602359c5
2 zmienionych plików z 2 dodań i 16 usunięć
  1. 1 14
      services/excel/lucky_sheet.go
  2. 1 2
      utils/common.go

+ 1 - 14
services/excel/lucky_sheet.go

@@ -1249,7 +1249,7 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 						}
 
 						if styleConfig.Decimal != nil {
-							tmp.Monitor = roundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
+							tmp.Monitor = utils.RoundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
 						} else {
 							if hasPercent {
 								numDecimal, _ := decimal.NewFromString(cell.ShowValue)
@@ -1308,16 +1308,3 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 
 	return
 }
-
-func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
-	numDecimal, _ := decimal.NewFromString(num)
-	if hasPercent {
-		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
-	}
-	numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
-	numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
-	if hasPercent {
-		numStr += "%"
-	}
-	return numStr
-}

+ 1 - 2
utils/common.go

@@ -1366,8 +1366,7 @@ func RoundNumber(num string, decimalPlaces int, hasPercent bool) string {
 	if hasPercent {
 		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
 	}
-	numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
-	numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
+	numStr := numDecimal.Round(int32(decimalPlaces)).StringFixed(int32(decimalPlaces))
 	if hasPercent {
 		numStr += "%"
 	}