|
@@ -1214,21 +1214,41 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
|
|
|
// changePointDecimalPlaces 小数点位数加减和百分比格式
|
|
|
func changePointDecimalPlaces(str string, changeNum int, numberType string, isPercent bool) (newStr string) {
|
|
|
newStr = str
|
|
|
+ var decimalPlaces int
|
|
|
+ dotIndex := strings.Index(newStr, ".") // 查找小数点的位置
|
|
|
+ if dotIndex == -1 {
|
|
|
+ decimalPlaces = 0
|
|
|
+ } else {
|
|
|
+ decimalPlaces = len(newStr) - dotIndex - 1
|
|
|
+ }
|
|
|
// 把字符串转成浮点数
|
|
|
val, _ := strconv.ParseFloat(str, 64)
|
|
|
if isPercent {
|
|
|
if numberType == "number" { //百分数转成小数
|
|
|
val = val / 100
|
|
|
+ decimalPlaces += 2
|
|
|
+ if decimalPlaces > 0 {
|
|
|
+ decimalPlaces = 0
|
|
|
+ }
|
|
|
isPercent = false
|
|
|
}
|
|
|
} else {
|
|
|
if numberType == "percent" {
|
|
|
+ if decimalPlaces > 2 {
|
|
|
+ decimalPlaces -= 2
|
|
|
+ }
|
|
|
val = val * 100
|
|
|
}
|
|
|
}
|
|
|
- newStr = fmt.Sprintf("%v", val)
|
|
|
- var decimalPlaces int // 计算小数位数
|
|
|
- dotIndex := strings.Index(newStr, ".") // 查找小数点的位置
|
|
|
+ if decimalPlaces > 0 {
|
|
|
+ val, _ = decimal.NewFromFloat(val).Round(int32(decimalPlaces)).Float64()
|
|
|
+ newStr = strconv.FormatFloat(val, 'f', decimalPlaces, 64)
|
|
|
+ } else {
|
|
|
+ newStr = fmt.Sprintf("%v", val)
|
|
|
+ }
|
|
|
+ // 计算小数位数
|
|
|
+ decimalPlaces = 0
|
|
|
+ dotIndex = strings.Index(newStr, ".") // 查找小数点的位置
|
|
|
if dotIndex == -1 {
|
|
|
decimalPlaces = 0
|
|
|
} else {
|