Reputation: 815
I have some values in excel sheet as 75.4
, 66.8
and some as integers 24554
. In database I have set the column type as varchar(11)
. The problem is that some decimal values are displaying correctly and some are displaying as 75.40000000000001
or 73.6
is read as 73.59000000
. I have 2 environments one local m/c and one workspace . In my local m/c it is showing correctly. So, I am not understanding what might be the issue. Following is my code
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$getValues = array();
for ($row = 4; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row); //gives the sheet values
if(!empty($rowData[0][0])){ //if row is null
// Insert row data array into database
$getValues[] = $this->getValuesModel($rowData, $data);
}
}
I doubt that there might be some php configuration setting because local and server are different but not sure. Kindly, guide me through this.
Upvotes: 1
Views: 1826
Reputation: 815
After digging a lot into this, I got the solution. We can do either of 2 the options:
format
of the cell defined in the excel sheet. It was given General , I changed it to Number and now values are exactly like in excel sheet.To override the floating number precision in ini file. PHPExcel modifies the precision and therefore following is the way we should do:
$iniPrecision = ini_get('precision');
$objPHPExcel = PHPExcel_IOFactory::load($inputFilename);
ini_set('precision', $iniPrecision);
Upvotes: 4