I want to write an array of floating point numbers into files
You can use the number_format
function to set a precision:
Example:
$mynum = 24.2837162893;
$mynum = number_format($mynum, 2);
echo($mynum);
// Outputs 24.28
So if you decide you want all your numbers to have 10 decimal places, you would just use $mynum = number_format($mynum, 10);
.
Also, see the sprintf() function for other formatting options.
[EDIT]
In your particular example, here is where you would use this function:
As described in the other answer, float values are inherently imprecise. You have to decide what precision is important to you in your use case.
Ref: http://php.net/manual/en/function.number-format.php