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

Small float does not get parsed correctly #1031

Closed
edhaz opened this issue Oct 4, 2021 · 2 comments
Closed

Small float does not get parsed correctly #1031

edhaz opened this issue Oct 4, 2021 · 2 comments
Labels
confirmed This issue can be reproduced

Comments

@edhaz
Copy link

edhaz commented Oct 4, 2021

Description

Parsing of a float ends up as a string. Number Format has no effect on it.

Steps to reproduce the issue:

  1. .xlsx file with 1 sheet with 0.00004 in cell A1 (General cell type).
  2. Attempt to change the style using "custom_number_format"
numberFmt := "0.00000"
styleID, err := output.NewStyle(&excelize.Style{CustomNumFmt: &numberFmt})
if err != nil {
    fmt.Println(err)
}
if err := output.SetCellStyle(sheetName, "A1", "A1", styleID); err != nil {
    fmt.Println(err)
}
  1. Get Rows from the sheet

Describe the results you received:
4.0000000000000003E-5

Describe the results you expected:
0.00004

Output of go version:

go version go1.17.1 darwin/arm64

Excelize version or commit ID:

v2.4.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):
macOS Big Sur 11.5.2
Microsoft Excel for Mac v16.53

@edhaz edhaz changed the title Float does not get parsed correctly Small float does not get parsed correctly Oct 5, 2021
@xuri
Copy link
Member

xuri commented Oct 7, 2021

Thanks for your feedback, I'm sorry that this library doesn't support parse custom number format and some scientific notation numeric with the default number format currently, it will return the raw value of the cell. Please try to convert it by yourself with cell type into your need format, for example:

num, err := strconv.ParseFloat("4.0000000000000003E-5", 64)
if err != nil {
    fmt.Println(err)
}
strconv.FormatFloat(num, 'f', -1, 64)

This issue also affects the time parse precision, also ref #1030, I'll fix it later.

@xuri xuri added the confirmed This issue can be reproduced label Oct 8, 2021
@xuri xuri added the in progress Working in progress label Oct 15, 2021
@xuri xuri closed this as completed in de38402 Oct 15, 2021
@edhaz
Copy link
Author

edhaz commented Oct 15, 2021

Thanks for all your work on this! 😄

@xuri xuri removed the in progress Working in progress label Oct 15, 2021
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
- new formula function: YEARFRAC, ref qax-os#65
- update the codecov version
- remove unused variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants