Phpexcel reading decimal numbers of Excel file is not read correctly

I have the value "9.2" (Dutch designation "9.2") in the cell of the .xlsx file, the cell has a "common" number format. Also, the value in the top bar, where you also view the formulas, says "9.2". When I read this cell using PHPExcel with → getValue (), I get "9,199999999999999".

This is my code:

$oPhpReader = PHPExcel_IOFactory::createReader($sFileType);
$aWorksheetNames = $oPhpReader->listWorksheetNames($sFileName);
$oPhpReader->setReadDataOnly(true);
$oPhpReader->setLoadSheetsOnly($aWorksheetNames[0]);
$oPhpExcel = $oPhpReader->load($sFileName);
$oWorksheet = $oPhpExcel->getActiveSheet();
$oCell = $oWorksheet->getCellByColumnAndRow($iCol,$iRow);
$sTempValue = $oCell->getValue();
+3
source share
1 answer

So I solved the problem now. Although I do not think this is a very neat solution, perhaps this is the only way.

I just realized that I would never get numbers with more than 12 digits only when PHPExcel is wrong. Therefore, I overtook all my floats to 12 digits using number_format:

if ((is_numeric($sTempValue))&&(strpos($sTempValue,'.')))
{
    $sTempValue = rtrim(rtrim(number_format($sTempValue,12,',',''),'0'),',');
}
+1