When you apply a numeric operation up to $num , it becomes a floating point number. 1e-06 and 0.000001 are textual representations of this number; the stored value does not distinguish between them.
If you just type or gate the number, it uses the default format, which, as you saw, leads to "1e-06" . Using sprintf with the format "%f" will give you a reasonable result; sprintf("%f", $num) gives "0.000001" .
But the format "%f" may lose information. For instance:
$num = "0.00000001"; printf("%f\n", $num);
prints:
0.000000
You say you want to print without each time determining how many digits will be displayed after the decimal point. Something must make this definition, and there is no universally correct way to do this. The obvious thing is to print only significant numbers, omitting trailing zeros, but this creates some problems. How many digits do you print for 1.0/3.0 whose decimal representation has an infinite 3 s sequence? And 0.00000001 cannot be represented exactly in binary floating point:
$num = "0.00000001"; printf("%f\n", $num); printf("%.78f\n", $num);
prints:
0.000000 0.000000010000000000000000209225608301284726753266340892878361046314239501953125
source share