You are not doing decimal math, but binary math. Perhaps the following will help you understand.

#!usr/bin/perl print " This program will print all 10 decimal places.\n"; print "Enter an integer value.\n"; $value =<STDIN>; #$value=1; #chop($value); $a = $value+1; print "$a\n"; while ($value<$a) { print "value has become $value\n"; $value=$value+0.1; print "Value after increment is :".sprintf('%20.17f',$value)." +\n" } print "EOF.\n";
result
This program will print all 10 decimal places. Enter an integer value. 10 11 value has become 10 Value after increment is :10.10000000000000000 value has become 10.1 Value after increment is :10.19999999999999900 value has become 10.2 Value after increment is :10.29999999999999900 value has become 10.3 Value after increment is :10.39999999999999900 value has become 10.4 Value after increment is :10.49999999999999800 value has become 10.5 Value after increment is :10.59999999999999800 value has become 10.6 Value after increment is :10.69999999999999800 value has become 10.7 Value after increment is :10.79999999999999700 value has become 10.8 Value after increment is :10.89999999999999700 value has become 10.9 Value after increment is :10.99999999999999600 value has become 11 Value after increment is :11.09999999999999600 EOF.


In reply to Re: While loop;s different behavior by huck
in thread While loop;s different behavior by Maahi

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.