0

Have another way to run this number generator? I want all the zeros. for exampe 0.00000000000000000000000009949 instead 9.949E-26

my code:

<?php
    ini_set('max_execution_time', 3000000000);
    $myfile = fopen("numbers.txt", "w") or die("Unable to open file!");
    for ($i = 0; $i <= 1; $i+= 0.000000000000000000000000000001) {
        $txt = $i.";";
        fwrite($myfile, $txt);
    }
    fclose($myfile);
?>
Kelvin Primo
  • 128
  • 12

2 Answers2

1

Look at number_format

for ($i = 0; $i <= 1; $i += 0.000000000000000000000000000001) {
    $txt = number_format($i, 30) . ";";
    fwrite($myfile, $txt);
}

This will give you all the zeros or even more, if you like. At least up to some precision, see Wikipedia - IEEE floating point for details.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

if PHP_MAX_INTEGER is not reached you can count down or up and add from left to a given length filling zeros and 0. to create the string and to prevent comma operations

like "0.".str_pad($i,30-strlen($i),'0', STR_PAD_LEFT)."$i\n"

JOUM
  • 239
  • 1
  • 3