|
@@ -6,13 +6,13 @@ import (
|
|
|
"eta/eta_api/models/data_manage/excel/request"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
+ "math"
|
|
|
"os"
|
|
|
"reflect"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/shopspring/decimal"
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
)
|
|
@@ -1763,58 +1763,41 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
|
|
|
}
|
|
|
showFormatValue := fmt.Sprintf("%v", cell.ShowFormatValue)
|
|
|
tmp.Monitor = showFormatValue
|
|
|
- _, err := strconv.ParseFloat(cell.ShowValue, 64)
|
|
|
+ tmpShowValue, err := strconv.ParseFloat(cell.Value, 64)
|
|
|
if err == nil {
|
|
|
- hasPercent := false
|
|
|
- if styleConfig.Nt == "percent" {
|
|
|
- hasPercent = true
|
|
|
- }
|
|
|
- if styleConfig.Decimal != nil {
|
|
|
- tmp.Monitor = roundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
|
|
|
- } else {
|
|
|
- if hasPercent {
|
|
|
- numDecimal, _ := decimal.NewFromString(cell.ShowValue)
|
|
|
- tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
|
|
|
- tmp.Monitor = tmpStr + "%"
|
|
|
+ switch styleConfig.Last {
|
|
|
+ case "nt":
|
|
|
+ // 先进行数字的百分比计算,然后保留小数点位数
|
|
|
+ percent := tmpShowValue * 100
|
|
|
+ if styleConfig.Decimal == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
+ rounded := math.Round(percent*factor) / factor
|
|
|
+ tmp.Monitor = fmt.Sprintf("%g%%", rounded)
|
|
|
+ case "decimal":
|
|
|
+ // 先保留小数点位数,再进行百分比计算
|
|
|
+ if styleConfig.Decimal == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
+ rounded := math.Round(tmpShowValue*factor) / factor
|
|
|
+ if styleConfig.Nt == "percent" {
|
|
|
+ percent := rounded * 100
|
|
|
+ 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 = cell.ShowValue
|
|
|
+ tmp.Monitor = fmt.Sprintf("%g", rounded)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // switch styleConfig.Last {
|
|
|
- // case "nt":
|
|
|
- // // 先进行数字的百分比计算,然后保留小数点位数
|
|
|
- // percent := tmpShowValue * 100
|
|
|
- // if styleConfig.Decimal == nil {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
- // rounded := math.Round(percent*factor) / factor
|
|
|
- // tmp.Monitor = fmt.Sprintf("%g%%", rounded)
|
|
|
- // case "decimal":
|
|
|
- // // 先保留小数点位数,再进行百分比计算
|
|
|
- // if styleConfig.Decimal == nil {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // factor := math.Pow(10, float64(*styleConfig.Decimal))
|
|
|
- // rounded := math.Round(tmpShowValue*factor) / factor
|
|
|
- // if styleConfig.Nt == "percent" {
|
|
|
- // percent := rounded * 100
|
|
|
- // 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)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
}
|
|
|
dataCol = append(dataCol, tmp)
|
|
|
}
|
|
@@ -1827,16 +1810,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
|
|
|
-}
|