Calculation functions change precision (round)

Topics: Developer Forum
Jan 11, 2011 at 2:40 PM

Hello,

I'am working with this librairy, I would like just to report something:

In the file /PHPExcel/Calculation/Functions.php at the top of the page, you could find the following code:

$savedPrecision = ini_get('precision');

if ($savedPrecision < 16) {
    ini_set('precision',16);
}

This change the current configuration of PHP, and after using PHPLibrairy, the value is not reset (in my case $savedPrecision = 12).

 

For exemple try this:

var_dump(round(8.71, 2));

//Before
if ($savedPrecision < 16) {
    ini_set('precision',16);
}

//After
var_dump(round(8.71, 2));

 

Result is:

//Before
float(8.71)
//After
float(8.710000000000001)



To solve the problem you could use the following code:
ini_set('precision',12);

after your following code:
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);

++