Files
PhpSpreadsheet/tests/data/Calculation/MathTrig/ROUNDDOWN.php
T
oleibman f553019f95 New Algorithm for TRUNC, ROUNDUP, and ROUNDDOWN
Fix #4113. TRUNC isn't always producing the expected result. There was a promising algorithm at https://stackoverflow.com/questions/4668628/truncate-float-numbers-with-php from user Juan. It works through Php8.3, but failed in Php8.4 (more on this later). User Savageman on the same page has a solution that needs work, but, once the work had taken place, it works on Php8.1-8.4.

The ROUNDUP and ROUNDDOWN functions were adversely affected by Php8.4, probably for the same reasons as Juan's TRUNC suggestion. I put a kludge in place for them some time ago, but I wasn't happy with it. The solution used for TRUNC here suggested a change to the ROUNDUP and ROUNDDOWN code that would no longer require the kludge. The change to those functions now works more cleanly on Php8.1-8.4.
2024-07-26 23:02:11 -07:00

38 lines
826 B
PHP

<?php
declare(strict_types=1);
return [
[0, '0,2'],
[662, '662.79,0'],
[662.7, '662.79, 1'],
[50, '54.1, -1'],
[50, '55.1, -1'],
[-23.6, '-23.67, 1'],
[3, '3.2, 0'],
[3, '3.2, 0.01'],
[76, '76.9, 0'],
[3.141, '3.14159, 3'],
[-3.1, '-3.14159,1'],
[31400, '31415.92654,"-2"'],
[31410, '31415.92654,-1'],
[4.44, '4.4400,2'],
[5.20, '2.26 + 2.94, 2'],
[-4.44, '-4.4400,2'],
[-5.20, '-2.26 - 2.94, 2'],
['#VALUE!', '"ABC",1'],
['#VALUE!', '1.234,"ABC"'],
[0, ', 0'],
[0, 'false, 0'],
[1, 'true, 0'],
['#VALUE!', '"", 0'],
[1, 'A2, 0'],
[2, 'A3, 0'],
[-3, 'A4, 0'],
[-5, 'A5, 0'],
[0, 'B1, 0'],
['exception', ''],
['exception', '35.51'],
'negative number and precision' => [-31400, '-31415.92654, -2'],
];