-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Loaded excel file didn't round decimal value correctly. #2385
Comments
My temporary fix is to change the code in PhpSpreadsheet/Style/NumberFormat/NumberFormatted.php inside the formatStraightNumericValue function from :
to :
I don't know how this will affect the other number formats aside from "0", so this is just temporary fix. |
PhpSpreadsheet is using |
Fix PHPOffice#2385. NumberFormatter is using sprintf on a float, and is seeing inconsistent rounding as a result (it will also occasionally result in `-0`). Change to round the number before presenting it to sprintf.
Fix #2385. NumberFormatter is using sprintf on a float, and is seeing inconsistent rounding as a result (it will also occasionally result in `-0`). Change to round the number before presenting it to sprintf.
This is:
What is the expected behavior?
Decimal value of 2,5 in excel got rounded to 3 when using Number cell format.
What is the current behavior?
When excel data is being retrieved using toArray(), the decimal value of 2,5 got rounded to 2 instead of 3. The rounding only works when the digit before the comma is an odd number (eg. 1,5 will be rounded to 2 and 23,5 will be rounded to 24 while 2,5 will be rounded to 2 and 22,5 will be rounded to 22 instead).
What are the steps to reproduce?
All I did was simply load the excel file
And the cell which is formatted to Number (Format code is "0") with the decimal value came out wrong as described in the current behavior :
Here's the excel if needed. The value I mention is on cell N7.
template_Bestorq (#21542) RING.xlsx
Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 1.19.0 and using PHP 7.4
The text was updated successfully, but these errors were encountered: