|
@@ -1227,12 +1227,12 @@ func changePointDecimalPlaces(str string, changeNum int, numberType string, isPe
|
|
|
if isPercent {
|
|
|
if numberType == "number" { //百分数转成小数
|
|
|
val = val / 100
|
|
|
- if decimalPlaces > 2 {
|
|
|
+ if decimalPlaces > 1 {
|
|
|
decimalPlaces += 2
|
|
|
} else if decimalPlaces == 1 {
|
|
|
decimalPlaces += 1
|
|
|
} else if decimalPlaces == 0 {
|
|
|
- if len(str) == 1 {
|
|
|
+ if len(str) == 1 || len(str) > 2 {
|
|
|
decimalPlaces = 2
|
|
|
} else if len(str) == 2 {
|
|
|
if str[1] == '0' {
|
|
@@ -1246,7 +1246,7 @@ func changePointDecimalPlaces(str string, changeNum int, numberType string, isPe
|
|
|
}
|
|
|
} else {
|
|
|
if numberType == "percent" {
|
|
|
- if decimalPlaces > 2 {
|
|
|
+ if decimalPlaces >= 2 {
|
|
|
decimalPlaces -= 2
|
|
|
} else if decimalPlaces == 1 {
|
|
|
decimalPlaces = 0
|
|
@@ -1258,7 +1258,8 @@ func changePointDecimalPlaces(str string, changeNum int, numberType string, isPe
|
|
|
val, _ = decimal.NewFromFloat(val).Round(int32(decimalPlaces)).Float64()
|
|
|
newStr = strconv.FormatFloat(val, 'f', decimalPlaces, 64)
|
|
|
} else {
|
|
|
- newStr = fmt.Sprintf("%v", val)
|
|
|
+ // 此处用%.f避免科学计数法, 从而导致后面出现很多位0
|
|
|
+ newStr = fmt.Sprintf("%.f", val)
|
|
|
}
|
|
|
// 计算小数位数
|
|
|
decimalPlaces = 0
|