Browse Source

fix:浮点数计算精度问题

zqbao 5 months ago
parent
commit
769517bf63
1 changed files with 8 additions and 1 deletions
  1. 8 1
      services/excel/lucky_sheet.go

+ 8 - 1
services/excel/lucky_sheet.go

@@ -1244,7 +1244,14 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 							rounded := math.Round(tmpShowValue*factor) / factor
 							if styleConfig.Nt == "percent" {
 								percent := rounded * 100
-								tmp.Monitor = fmt.Sprintf("%g%%", percent)
+								var precisionStr string
+								if *styleConfig.Decimal > 2 {
+									precision := *styleConfig.Decimal - 2
+									precisionStr = strconv.FormatFloat(rounded, 'f', precision, 64)
+								} else {
+									precisionStr = strconv.FormatFloat(math.Round(percent), 'f', -1, 64)
+								}
+								tmp.Monitor = fmt.Sprintf("%s%%", precisionStr)
 							} else {
 								tmp.Monitor = fmt.Sprintf("%g", rounded)
 							}