You are not doing decimal math, but binary math. Perhaps the following will help you understand.
result#!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";
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |