Skip to content

Commit 58ff149

Browse files
committed
Additional Examples Which Were Failing
1 parent f553019 commit 58ff149

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public static function evaluate(array|float|string|null $value = 0, array|int|st
5151

5252
return ($minusSign === '') ? $result : -$result;
5353
}
54-
$digitsPlus1 = $digits + 1;
55-
$result = substr($minusSign . sprintf("%.{$digitsPlus1}f", $value), 0, -1);
54+
$resultString = (string) $value;
55+
$regExp = '/([.]\\d{' . $digits . '})\\d+$/';
56+
$result = $minusSign . (preg_replace($regExp, '$1', $resultString) ?? $resultString);
5657

5758
return (float) $result;
5859
}

tests/data/Calculation/MathTrig/TRUNC.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@
4141
'issue4113 small negative fraction keep all' => [-0.04, '-0.04, 2'],
4242
'issue4113 small fraction lose some' => [0.0, '0.01, 1'],
4343
'issue4113 small negative fraction lose some' => [0.0, '-0.001, 1'],
44+
'issue4113 example 3' => [-43747, '-43747.99122596, 0'],
45+
'issue4113 example 3 positive' => [43747, '43747.99122596, 0'],
46+
'issue4113 example 4' => [-9.11, '-9.1196419, 2'],
47+
'issue4113 example 5' => [-42300.65, '-42300.65099338, 3'],
4448
];

0 commit comments

Comments
 (0)