|
@@ -1226,38 +1226,26 @@ 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(str, ".") // 查找小数点的位置
|
|
|
- if dotIndex == -1 {
|
|
|
- decimalPlaces = 0
|
|
|
- } else {
|
|
|
- decimalPlaces = len(str) - dotIndex - 1
|
|
|
- }
|
|
|
-
|
|
|
// 把字符串转成浮点数
|
|
|
val, _ := strconv.ParseFloat(str, 64)
|
|
|
-
|
|
|
if isPercent {
|
|
|
if numberType == "number" { //百分数转成小数
|
|
|
- if decimalPlaces == 0 {
|
|
|
- if len(str) < 3 {
|
|
|
- decimalPlaces = decimalPlaces + 2
|
|
|
- } else if len(str) == 3 {
|
|
|
- decimalPlaces = decimalPlaces + 1
|
|
|
- }
|
|
|
- } else {
|
|
|
- decimalPlaces = decimalPlaces + 2
|
|
|
- }
|
|
|
val = val / 100
|
|
|
isPercent = false
|
|
|
}
|
|
|
} else {
|
|
|
if numberType == "percent" {
|
|
|
val = val * 100
|
|
|
- decimalPlaces = decimalPlaces - 2
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ newStr = fmt.Sprintf("%v", val)
|
|
|
+ var decimalPlaces int // 计算小数位数
|
|
|
+ dotIndex := strings.Index(newStr, ".") // 查找小数点的位置
|
|
|
+ if dotIndex == -1 {
|
|
|
+ decimalPlaces = 0
|
|
|
+ } else {
|
|
|
+ decimalPlaces = len(newStr) - dotIndex - 1
|
|
|
+ }
|
|
|
decimalPlaces += changeNum
|
|
|
|
|
|
if decimalPlaces < 0 {
|