Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.CalcCellValue returns wrong value for "=ROUND(1444.00000000000003,2)" #1851

Closed
alexbrainman-anz opened this issue Mar 18, 2024 · 2 comments · Fixed by #1860
Closed

File.CalcCellValue returns wrong value for "=ROUND(1444.00000000000003,2)" #1851

alexbrainman-anz opened this issue Mar 18, 2024 · 2 comments · Fixed by #1860
Labels
bug Something isn't working
Projects

Comments

@alexbrainman-anz
Copy link

Description

I am using

=ROUND(1444.00000000000003,2)

formula in my Excel files.

I am calling File.CalcCellValue method on those formulas with Options{RawCellValue: true} option. I expect to see no digits after decimal point, but I see 1444.0000000000002 returned.

Steps to reproduce the issue:

I used this commit 4eb088c .

I made these changes to the code:

diff --git a/calc_test.go b/calc_test.go
index 71d0acd..2ce7908 100644
--- a/calc_test.go
+++ b/calc_test.go
@@ -6317,6 +6317,8 @@ func TestFormulaRawCellValueOption(t *testing.T) {
                {"=\"10\" & \"e3\"", true, "10e3"},
                {"=\"1111111111111111\"", false, "1.11111111111111E+15"},
                {"=\"1111111111111111\"", true, "1111111111111111"},
+               {"=ROUND(1444.00000000000003,2)", false, "1444"},
+               {"=ROUND(1444.00000000000003,2)", true, "1444"},
        }
        for _, test := range rawTest {
                assert.NoError(t, f.SetCellFormula("Sheet1", "A1", test.value))

I run this command:

go test -run=TestFormulaRawCellValueOption

Describe the results you received:

I see this output:

--- FAIL: TestFormulaRawCellValueOption (0.00s)
    calc_test.go:6327:
                Error Trace:    /Users/brainmaa/src/github.com/qax-os/excelize/calc_test.go:6327
                Error:          Not equal:
                                expected: "1444"
                                actual  : "1444.0000000000002"

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -1444
                                +1444.0000000000002
                Test:           TestFormulaRawCellValueOption
FAIL
exit status 1
FAIL    github.com/xuri/excelize/v2     0.183s

Describe the results you expected:

PASS
ok    github.com/xuri/excelize/v2     0.183s

Output of go version:

go version go1.21.6 darwin/arm64

Excelize version or commit ID:

4eb088cf7

Environment details (OS, Microsoft Excel™ version, physical, etc.):

I use MacOS. I do not have Excel installed.

This code used to work properly before a258e3d - I used git bisect to find that.

Thank you very much for your assistance.

Alex

@xuri xuri added the bug Something isn't working label Mar 19, 2024
@xuri xuri added this to Bugfix in v2.9.0 Mar 19, 2024
realzuojianxiang added a commit to realzuojianxiang/excelize that referenced this issue Mar 22, 2024
@xuri xuri linked a pull request Mar 22, 2024 that will close this issue
10 tasks
xuri pushed a commit that referenced this issue Mar 22, 2024
…und issue (#1860)

- The SetSheetName function now support case sensitivity
- Update unit tests
@xuri
Copy link
Member

xuri commented Mar 22, 2024

Thanks for your issue. This issue has been fixed, please upgrade to the master branch by go get -u github.com/xuri/excelize/v2@master, and this patch will be released in the next version.

@alexbrainman-anz
Copy link
Author

This issue has been fixed, please upgrade to the master branch by go get -u github.com/xuri/excelize/v2@master, and this patch will be released in the next version.

Thank you very much for fixing the bug so quickly.

Excellent job.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
v2.9.0
Bugfix
Development

Successfully merging a pull request may close this issue.

2 participants