Skip to content

Commit 9450bc1

Browse files
authored
Merge branch 'master' into issue4128
2 parents 4500f5a + 1c77e00 commit 9450bc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+121
-144
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2727

2828
- Html Reader Preserve Unicode Whitespace. [Issue #1284](https://github.com/PHPOffice/PhpSpreadsheet/issues/1284) [PR #4106](https://github.com/PHPOffice/PhpSpreadsheet/pull/4106)
2929
- RATE Function Floating Point Number of Periods. [PR #4107](https://github.com/PHPOffice/PhpSpreadsheet/pull/4107)
30+
- Parameter Name Change Xlsx Writer Workbook. [Issue #4108](https://github.com/PHPOffice/PhpSpreadsheet/issues/4108) [PR #4111](https://github.com/PHPOffice/PhpSpreadsheet/pull/4111)
31+
- New Algorithm for TRUNC, ROUNDUP, ROUNDDOWN. [Issue #4113](https://github.com/PHPOffice/PhpSpreadsheet/issues/4113) [PR #4115](https://github.com/PHPOffice/PhpSpreadsheet/pull/4115)
3032

3133
## 2024-07-29 - 2.2.1
3234

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class Calculation
6969

7070
/**
7171
* Instance of this class.
72-
*
73-
* @var ?Calculation
7472
*/
7573
private static ?Calculation $instance = null;
7674

@@ -3272,10 +3270,8 @@ private static function translateFormula(array $from, array $to, string $formula
32723270
return $formula;
32733271
}
32743272

3275-
/** @var ?array */
32763273
private static ?array $functionReplaceFromExcel;
32773274

3278-
/** @var ?array */
32793275
private static ?array $functionReplaceToLocale;
32803276

32813277
/**
@@ -3321,10 +3317,8 @@ public function translateFormulaToLocale(string $formula): string
33213317
);
33223318
}
33233319

3324-
/** @var ?array */
33253320
private static ?array $functionReplaceFromLocale;
33263321

3327-
/** @var ?array */
33283322
private static ?array $functionReplaceToExcel;
33293323

33303324
/**

src/PhpSpreadsheet/Calculation/MathTrig/Round.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class Round
1010
{
1111
use ArrayEnabled;
1212

13-
private const ROUNDING_ADJUSTMENT = (PHP_VERSION_ID < 80400) ? 0 : 1e-14;
14-
1513
/**
1614
* ROUND.
1715
*
@@ -69,11 +67,22 @@ public static function up($number, $digits): array|string|float
6967
return 0.0;
7068
}
7169

70+
$digitsPlus1 = $digits + 1;
7271
if ($number < 0.0) {
73-
return round($number - 0.5 * 0.1 ** $digits + self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_DOWN);
72+
if ($digitsPlus1 < 0) {
73+
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
74+
}
75+
$result = sprintf("%.{$digitsPlus1}F", $number - 0.5 * 0.1 ** $digits);
76+
77+
return round((float) $result, $digits, PHP_ROUND_HALF_DOWN);
78+
}
79+
80+
if ($digitsPlus1 < 0) {
81+
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
7482
}
83+
$result = sprintf("%.{$digitsPlus1}F", $number + 0.5 * 0.1 ** $digits);
7584

76-
return round($number + 0.5 * 0.1 ** $digits - self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_DOWN);
85+
return round((float) $result, $digits, PHP_ROUND_HALF_DOWN);
7786
}
7887

7988
/**
@@ -105,11 +114,23 @@ public static function down($number, $digits): array|string|float
105114
return 0.0;
106115
}
107116

117+
$digitsPlus1 = $digits + 1;
108118
if ($number < 0.0) {
109-
return round($number + 0.5 * 0.1 ** $digits - self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_UP);
119+
if ($digitsPlus1 < 0) {
120+
return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
121+
}
122+
$result = sprintf("%.{$digitsPlus1}F", $number + 0.5 * 0.1 ** $digits);
123+
124+
return round((float) $result, $digits, PHP_ROUND_HALF_UP);
125+
}
126+
127+
if ($digitsPlus1 < 0) {
128+
return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
110129
}
111130

112-
return round($number - 0.5 * 0.1 ** $digits + self::ROUNDING_ADJUSTMENT, $digits, PHP_ROUND_HALF_UP);
131+
$result = sprintf("%.{$digitsPlus1}F", $number - 0.5 * 0.1 ** $digits);
132+
133+
return round((float) $result, $digits, PHP_ROUND_HALF_UP);
113134
}
114135

115136
/**

src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class Trunc
1313
* TRUNC.
1414
*
1515
* Truncates value to the number of fractional digits by number_digits.
16+
* This will probably not be the precise result in the unlikely
17+
* event that the number of digits to the left of the decimal
18+
* plus the number of digits to the right exceeds PHP_FLOAT_DIG
19+
* (or possibly that value minus 1).
20+
* Excel is unlikely to do any better.
1621
*
1722
* @param array|float $value Or can be an array of values
1823
* @param array|int $digits Or can be an array of values
@@ -34,15 +39,27 @@ public static function evaluate(array|float|string|null $value = 0, array|int|st
3439
return $e->getMessage();
3540
}
3641

37-
$digits = floor($digits);
42+
if ($value == 0) {
43+
return $value;
44+
}
3845

39-
// Truncate
40-
$adjust = 10 ** $digits;
46+
if ($value >= 0) {
47+
$minusSign = '';
48+
} else {
49+
$minusSign = '-';
50+
$value = -$value;
51+
}
52+
$digits = (int) floor($digits);
53+
if ($digits < 0) {
54+
$result = (float) (substr(sprintf('%.0F', $value), 0, $digits) . str_repeat('0', -$digits));
4155

42-
if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
43-
return $value;
56+
return ($minusSign === '') ? $result : -$result;
4457
}
58+
$decimals = (floor($value) == (int) $value) ? (PHP_FLOAT_DIG - strlen((string) (int) $value)) : $digits;
59+
$resultString = ($decimals < 0) ? sprintf('%F', $value) : sprintf('%.' . $decimals . 'F', $value);
60+
$regExp = '/([.]\\d{' . $digits . '})\\d+$/';
61+
$result = $minusSign . (preg_replace($regExp, '$1', $resultString) ?? $resultString);
4562

46-
return ((int) ($value * $adjust)) / $adjust;
63+
return (float) $result;
4764
}
4865
}

src/PhpSpreadsheet/Cell/Cell.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class Cell implements Stringable
5050

5151
/**
5252
* The collection of cells that this cell belongs to (i.e. The Cell Collection for the parent Worksheet).
53-
*
54-
* @var ?Cells
5553
*/
5654
private ?Cells $parent;
5755

src/PhpSpreadsheet/Chart/Properties.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ abstract class Properties
105105

106106
protected bool $objectState = false; // used only for minor gridlines
107107

108-
/** @var ?float */
109108
protected ?float $glowSize = null;
110109

111110
protected ChartColor $glowColor;

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,10 @@ class Html
533533
'yellowgreen' => '9acd32',
534534
];
535535

536-
/** @var ?string */
537536
private ?string $face = null;
538537

539-
/** @var ?string */
540538
private ?string $size = null;
541539

542-
/** @var ?string */
543540
private ?string $color = null;
544541

545542
private bool $bold = false;

src/PhpSpreadsheet/Reader/Csv/Delimiter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Delimiter
1717

1818
protected int $numberLines = 0;
1919

20-
/** @var ?string */
2120
protected ?string $delimiter = null;
2221

2322
/**

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ class Xls extends BaseReader
350350

351351
/**
352352
* The current RC4 decryption object.
353-
*
354-
* @var ?Xls\RC4
355353
*/
356354
private ?Xls\RC4 $rc4Key = null;
357355

0 commit comments

Comments
 (0)