Extra Decimal Places with Certain Number Values

Topics: Developer Forum, User Forum
Apr 24, 2014 at 7:24 PM
I have been using PHPExcel 1.8 to accept uploaded spreadsheets containing scientific values. I noticed today that certain numeric values in .xlsx and .ods worksheets result in extra decimal places for no reason.

Values that cause this error include:
93.18
0.69
8.043
94.9
93.6
89.9
96.1
0.56

My PHP code is as follows:
<?

include 'PHPExcel/IOFactory.php';

$inputFileName="decimal_places_error.xlsx";

$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);

$objPHPExcel->setActiveSheetIndex(0);

$sd = $objPHPExcel->getActiveSheet()->toArray();

print_r($sd);

?>
The above code results in:
Array
(
    [0] => Array
        (
            [0] => 93.18000000000001
        )

    [1] => Array
        (
            [0] => 0.6899999999999999
        )

    [2] => Array
        (
            [0] => 8.042999999999999
        )

    [3] => Array
        (
            [0] => 94.90000000000001
        )

    [4] => Array
        (
            [0] => 93.59999999999999
        )

    [5] => Array
        (
            [0] => 89.90000000000001
        )

    [6] => Array
        (
            [0] => 96.09999999999999
        )

    [7] => Array
        (
            [0] => 0.5600000000000001
        )

)
The above error occurs in PHPExcel 1.8, but as a test I also tried 1.79 and 1.78.

1.79 also has the error, but 1.78 does not. As a result, I have rolled back to 1.78 for the time being.

I will attach a file "decimal_places_error.xlsx" to the file uploads post for testing.