#2414·excelize

A negative zero is not equal to zero in = and <> and is not counted by COUNTIF

Author: PhilflowIOCreated Sep 20, 2026Updated Sep 20, 2026

Description

newNumberFormulaArg (calc.go:978) passes a negative zero through unchanged. It formats as "-0", and the equality operators compare the formatted text of their operands, so x = 0 is FALSE and x <> 0 is TRUE for a value that is zero. COUNTIF sees the same thing and does not go through the comparison operators at all.

A negative zero is easy to produce: (condition)*-1 yields one as soon as the condition is false.

The ordering operators compare the numbers and are not affected, which is why only equality shows it.

There is no error. A row guarded by x <> 0 is counted when it should be skipped.

Steps to reproduce the issue

go
package main

import (
	"fmt"

	"github.com/xuri/excelize/v2"
)

func main() {
	f := excelize.NewFile()
	f.SetCellFormula("Sheet1", "A1", `=(1=2)*-1`)
	f.SetCellFormula("Sheet1", "A2", `=(1=2)*-1`)
	for _, formula := range []string{
		`=A1`,
		`=A1=0`,
		`=A1<>0`,
		`=IF(A1<>0,"counted","skipped")`,
		`=COUNTIF(A1:A2,0)`,
	} {
		f.SetCellFormula("Sheet1", "C1", formula)
		result, err := f.CalcCellValue("Sheet1", "C1")
		fmt.Printf("%-32s %-10q %v\n", formula, result, err)
	}
}

Describe the results you received

=A1                              "-0"        <nil>
=A1=0                            "FALSE"     <nil>
=A1<>0                           "TRUE"      <nil>
=IF(A1<>0,"counted","skipped")   "counted"   <nil>
=COUNTIF(A1:A2,0)                "0"         <nil>

Describe the results you expected

=A1                              "0"         <nil>
=A1=0                            "TRUE"      <nil>
=A1<>0                           "FALSE"     <nil>
=IF(A1<>0,"counted","skipped")   "skipped"   <nil>
=COUNTIF(A1:A2,0)                "2"         <nil>

Go version

go version go1.26.8 linux/amd64

Excelize version or commit ID

0434413

Environment

GOOS='linux'
GOARCH='amd64'
CGO_ENABLED='1'
GOVERSION='go1.26.8'