未验证 提交 f753e560 编写于 作者: M magicrabbit 提交者: GitHub

Fix number format scientific notation zero fill issues (#1710)

上级 4e936daf
......@@ -4953,7 +4953,7 @@ func (nf *numberFormat) numberHandler() string {
fracLen = nf.fracPadding
}
if isNum, precision, decimal := isNumeric(nf.value); isNum {
if precision > 15 && intLen+fracLen > 15 {
if precision > 15 && intLen+fracLen > 15 && !nf.useScientificNotation {
return nf.printNumberLiteral(nf.printBigNumber(decimal, fracLen))
}
}
......@@ -4961,14 +4961,13 @@ func (nf *numberFormat) numberHandler() string {
if fracLen > 0 {
paddingLen++
}
flag := "f"
fmtCode := fmt.Sprintf("%%0%d.%df%s", paddingLen, fracLen, strings.Repeat("%%", nf.percent))
if nf.useScientificNotation {
if nf.expBaseLen != 2 {
return nf.value
}
flag = "E"
fmtCode = fmt.Sprintf("%%.%dE%s", fracLen, strings.Repeat("%%", nf.percent))
}
fmtCode := fmt.Sprintf("%%0%d.%d%s%s", paddingLen, fracLen, flag, strings.Repeat("%%", nf.percent))
if nf.percent > 0 {
num *= math.Pow(100, float64(nf.percent))
}
......
......@@ -3539,6 +3539,8 @@ func TestNumFmt(t *testing.T) {
{"8.8888666665555493e+19", "#,000.00", "88,888,666,665,555,500,000.00"},
{"8.8888666665555493e+19", "0.00000", "88888666665555500000.00000"},
{"37947.7500001", "0.00000000E+00", "3.79477500E+04"},
{"2312312321.1231198", "0.00E+00", "2.31E+09"},
{"3.2234623764278598E+33", "0.00E+00", "3.22E+33"},
{"1.234E-16", "0.00000000000000000000", "0.00000000000000012340"},
{"1.234E-16", "0.000000000000000000", "0.000000000000000123"},
{"1.234E-16", "0.000000000000000000%", "0.000000000000012340%"},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册