If you really need to assign strings, you will have to force the scalar into a number afterwards
DB<1> $d1 = '1230.1200'; DB<2> print $d1 1230.1200 DB<3> print $d1+0 1230.12 DB<4> $d1=$d1+0 DB<5> print $d1 1230.12

Cheers Rolf

UPDATE: Please be aware about the limitations of floating-point-numbers as illustrated in the folowing example

DB<1> $a='0.0000001'; DB<2> print $a+0 1e-07 DB<3> printf "%s",$a 0.0000001 DB<4> $a=sprintf "%s",$a DB<5> print $a 0.0000001 DB<7> $a='0.00000000000000000000000000000000001000000000000000'; DB<8> $a=sprintf "%s",$a+0 DB<9> print $a 1e-35

If you just wanna reformat a string avoiding any float-representation , you should better consider taking the regex from kennethk's posting!


In reply to Re: substitution "0" in decimals by LanX
in thread substitution "0" in decimals by Sun751

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.