You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#4626. Previous changes had increased the precision of floating point numbers when cast to string, making for greater accuracy after save and load operations, without affecting the values displayed by Excel. Although the results of the cast are now more accurate computationally, they can appear unexpected to humans. A new boolean parameter `lessFloatPrecision` (defaulting to false) is added to `StringHelper::convertToString`, to `NumberFormat::toFormattedString` and `NumberFormat\Formatter::toFormattedString`, and to the entire `Worksheet::toArray` family of functions. When the new parameter is set to true, the result can be less surprising to humans. It should not, however, be used in subsequent computations.
In the case of the NumberFormat functions, the new parameter will be considered only when the NumberFormat for the cell in question is `General` or equivalent. Setting an actual numeric format for the cell is probably a better solution than using the new parameter.
Copy file name to clipboardExpand all lines: docs/topics/Looping the Loop.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,9 @@ It can return the raw cell value (which isn't particularly useful if the cell co
57
57
| $calculateFormulas | boolean | false | Flag to indicate if formula values should be calculated before returning. |
58
58
| $formatData | boolean | false | Flag to request that values should be formatting before returning. |
59
59
| $returnCellRef | boolean | false | False - Return a simple enumerated array of rows and columns (indexed by number counting from zero)<br />True - Return rows and columns indexed by their actual row and column IDs. |
| $reduceArrays | boolean | false | True - If calculated value is an array, reduce it to top leftmost value. |
62
+
| $lessFloatPrecision | boolean | false | True - PhpSpreadsheet 5.2+ - Floats, if formatted, will display as a more human-friendly but possibly less accurate value. |
Copy file name to clipboardExpand all lines: src/PhpSpreadsheet/Worksheet/Worksheet.php
+31-12Lines changed: 31 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -2949,12 +2949,15 @@ public function fromArray(array $source, mixed $nullValue = null, string $startC
2949
2949
}
2950
2950
2951
2951
/**
2952
+
* @param bool $calculateFormulas Whether to calculate cell's value if it is a formula.
2952
2953
* @param null|bool|float|int|RichText|string $nullValue value to use when null
2954
+
* @param bool $formatData Whether to format data according to cell's style.
2955
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
* True - Return rows and columns indexed by their actual row and column IDs
2990
2994
* @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
2991
2995
* True - Don't return values for rows/columns that are defined as hidden.
2996
+
* @param bool $reduceArrays If true and result is a formula which evaluates to an array, reduce it to the top leftmost value.
2997
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
2992
2998
*
2993
2999
* @return mixed[][]
2994
3000
*/
@@ -2999,12 +3005,13 @@ public function rangeToArray(
@@ -3022,6 +3029,8 @@ public function rangeToArray(
3022
3029
* True - Return rows and columns indexed by their actual row and column IDs
3023
3030
* @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
3024
3031
* True - Don't return values for rows/columns that are defined as hidden.
3032
+
* @param bool $reduceArrays If true and result is a formula which evaluates to an array, reduce it to the top leftmost value.
3033
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
3025
3034
*
3026
3035
* @return mixed[][]
3027
3036
*/
@@ -3032,14 +3041,15 @@ public function rangesToArray(
@@ -3058,6 +3068,8 @@ public function rangesToArray(
3058
3068
* True - Return rows and columns indexed by their actual row and column IDs
3059
3069
* @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
3060
3070
* True - Don't return values for rows/columns that are defined as hidden.
3071
+
* @param bool $reduceArrays If true and result is a formula which evaluates to an array, reduce it to the top leftmost value.
3072
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
3061
3073
*
3062
3074
* @return Generator<array<mixed>>
3063
3075
*/
@@ -3068,7 +3080,8 @@ public function rangeToArrayYieldRows(
@@ -3214,6 +3227,8 @@ private function validateNamedRange(string $definedName, bool $returnNullIfInval
3214
3227
* True - Return rows and columns indexed by their actual row and column IDs
3215
3228
* @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
3216
3229
* True - Don't return values for rows/columns that are defined as hidden.
3230
+
* @param bool $reduceArrays If true and result is a formula which evaluates to an array, reduce it to the top leftmost value.
3231
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
3217
3232
*
3218
3233
* @return mixed[][]
3219
3234
*/
@@ -3224,7 +3239,8 @@ public function namedRangeToArray(
@@ -3250,6 +3266,8 @@ public function namedRangeToArray(
3250
3266
* True - Return rows and columns indexed by their actual row and column IDs
3251
3267
* @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden.
3252
3268
* True - Don't return values for rows/columns that are defined as hidden.
3269
+
* @param bool $reduceArrays If true and result is a formula which evaluates to an array, reduce it to the top leftmost value.
3270
+
* @param bool $lessFloatPrecision If true, formatting unstyled floats will convert them to a more human-friendly but less computationally accurate value
0 commit comments