worldofwires
asked on
Engineering Units in PHP
Hi,
I'm having issues when exporting data to a csv file via the fopen method. Any large float (above about 20million) is being converted into engineering units. Not a problem if the destination prog was Excel but it's not and it's error as a string.
I'm currently writing a hack to covert big numbers into integers, losing the accuracy but not much (they're currency values).
Thanks for any help,
John
I'm having issues when exporting data to a csv file via the fopen method. Any large float (above about 20million) is being converted into engineering units. Not a problem if the destination prog was Excel but it's not and it's error as a string.
I'm currently writing a hack to covert big numbers into integers, losing the accuracy but not much (they're currency values).
Thanks for any help,
John
What do you mean by the "fopen method?" Can you show us the code and a bit of test data? Thanks, ~Ray
ASKER
Ray,
I don't really have any test data as it's confidential information. Just a rows of number between 1 and 25 million with 2 decimal places will prove the point. The code is something like...
My hack seems to work so I suspect it's just the length of the floatval() that caused the issue. 2 DP when over a million hardly seems worrying about when talking about currency.
Thanks,
John
P.S. Also, the $apro array could be...
I don't really have any test data as it's confidential information. Just a rows of number between 1 and 25 million with 2 decimal places will prove the point. The code is something like...
if($f=fopen($oslocale."data/dumps/".$fn.".csv", "w")) {
fputcsv($f, $apro, ',', '"');
}
fclose($f);
My hack seems to work so I suspect it's just the length of the floatval() that caused the issue. 2 DP when over a million hardly seems worrying about when talking about currency.
Thanks,
John
P.S. Also, the $apro array could be...
$apro=array(floatval(25000000.00), intval(25000000));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Run this and see if you get the same thing on your server that I get here:
http://www.laprbass.com/RAY_temp_worldofwires.php
http://www.laprbass.com/RAY_temp_worldofwires.php
<?php // RAY_temp_worldofwires.php
error_reporting(E_ALL);
echo "<pre>";
$apro=array(floatval(25000000.00), intval(25000000));
// var_dump($apro);
// WHAT IS THE MAXIMUM INTEGER ON THIS SERVER?
var_dump(PHP_INT_MAX);
ASKER
Ray,
It returns: int(2147483647).
The problem seems to be resolved when converting floats to ints for the bigger values.
Thanks for your help,
John
It returns: int(2147483647).
The problem seems to be resolved when converting floats to ints for the bigger values.
Thanks for your help,
John
Thanks for the points - it's a great question! All the best, ~Ray