This closes #1942, fix percent sign missing in formatted result for zero numeric cell value (#1947)

- Updated unit tests
This commit is contained in:
wxy 2024-07-12 08:07:19 +08:00 committed by GitHub
parent 431c31029e
commit 307e533061
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 22 deletions

View File

@ -4799,10 +4799,8 @@ func format(value, numFmt string, date1904 bool, cellType CellType, opts *Option
switch section.Type {
case nfp.TokenSectionPositive:
return nf.alignmentHandler(nf.positiveHandler())
case nfp.TokenSectionNegative:
return nf.alignmentHandler(nf.negativeHandler())
default:
return nf.alignmentHandler(nf.zeroHandler())
return nf.alignmentHandler(nf.negativeHandler())
}
}
return nf.alignmentHandler(nf.textHandler())
@ -7108,11 +7106,6 @@ func (nf *numberFormat) negativeHandler() (result string) {
return nf.numberHandler()
}
// zeroHandler will be handling zero selection for a number format expression.
func (nf *numberFormat) zeroHandler() string {
return nf.value
}
// textHandler will be handling text selection for a number format expression.
func (nf *numberFormat) textHandler() (result string) {
for _, token := range nf.section[nf.sectionIdx].Items {
@ -7137,10 +7130,9 @@ func (nf *numberFormat) getValueSectionType(value string) (float64, string) {
return 0, nfp.TokenSectionText
}
number, _ := strconv.ParseFloat(value, 64)
if number > 0 {
if number >= 0 {
return number, nfp.TokenSectionPositive
}
if number < 0 {
var hasNeg bool
for _, sec := range nf.section {
if sec.Type == nfp.TokenSectionNegative {
@ -7152,6 +7144,4 @@ func (nf *numberFormat) getValueSectionType(value string) (float64, string) {
return number, nfp.TokenSectionPositive
}
return number, nfp.TokenSectionNegative
}
return number, nfp.TokenSectionZero
}

View File

@ -69,7 +69,10 @@ func TestNumFmt(t *testing.T) {
{"0.97952546296296295", "h:m", "23:30"},
{"43528", "mmmm", "March"},
{"43528", "dddd", "Monday"},
{"0", ";;;", "0"},
{"0", ";;;", ""},
{"0", "0%", "0%"},
{"0", "0.0%", "0.0%"},
{"0", "0.00%", "0.00%"},
{"43528", "[$-409]MM/DD/YYYY", "03/04/2019"},
{"43528", "[$-409]MM/DD/YYYY am/pm", "03/04/2019 AM"},
{"43528", "[$-111]MM/DD/YYYY", "43528"},