in reply to Re^2: substitution "0" in decimals
in thread substitution "0" in decimals

> It may not matter for the OP, but at least he should be made aware of when using this trick.

see footnotes in Re^3: substitution "0" in decimals

Anyway I'm not sure if a conversion to float (resulting in information loss) really happens when stored or just during some numerical calculations:

DB<4> $d1 = "1230.1200"; DB<5> $d1 = $d1 + 0; DB<6> print $d1."00" 1230.1200

Cheers Rolf

Replies are listed 'Best First'.
Re^4: substitution "0" in decimals
by JavaFan (Canon) on Dec 08, 2009 at 12:57 UTC
    In happens when converting to floats. Now, when converting floats to strings, Perl only uses a limited (6?) number of digits after the decimal point, if the number before the decimal point isn't 0. In this case (and many others), this cancels out the loss of significance.

    In many cases, you will not notice the difference, Perl will just "do what I mean". But sometimes, you'll be surprised. String to float and back isn't always free.

      I was wondering if it is really stored as a float.

      your explanation with limited number of digits is good ( I was thinking of that), but should include rounding!

      > In many cases, you will not notice the difference, Perl will just "do what I mean". But sometimes, you'll be surprised. String to float and back isn't always free.

      Plz, can you give me an example?

      UPDATE: Never mind, see update to Re: substitution "0" in decimals!

      Cheers Rolf