Hi Monks
I came across with a strange result when I'm using int() function. For example,
my $x1 = (1.15*170)+0.50;
my $x2 = int($x1);
print "Number is: $x1, Integer part is: $x2";
It prints "Number is: 196, Integer part is: 195", but I would expect $x2 to be 196
But when I am using different numbers I am getting the correct results. For example,
my $x1 = (1.15*150)+0.50;
my $x2 = int($x1);
print "\nNumber is: $x1, Integer part is: $x2";
my $x1 = (1.15*30)+0.50;
my $x2 = int($x1);
print "\nNumber is: $x1, Integer part is: $x2";
Can anybody guess what goes wrong with the first one, what goes wrong when I'm using the number 170? At least, I would expect either all results be correct or all results be wrong, but not just one be wrong.
Using int(sprintf("%.2f",$x1)) fixes the error but this is not the issue.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.