PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

Incorrectly imported price #929

Open Aligan opened 8 years ago

Aligan commented 8 years ago

The file is 544.81 price, and online 544.8099999999999 I getting value for money: $price = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(4, $i)->getValue();

MarkBaker commented 8 years ago

This is not an issue with PHPExcel, this is called ROUNDING

Aligan commented 8 years ago

Help me! round() not working

MarkBaker commented 8 years ago

What do you mean "round() not working"? round() is a standard PHP function, that works pretty effectively:

$price = 544.8099999999999;
echo round($price, 2);

Demo

Alternatively, if you have formatting for your cells, then use:

$price = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(4, $i)->getFormattedValue();

As described in the PHPExcel Documentation