The numbers have maximum 2 digits.
The code is just for debugging, extracting the problem from a larger code, to have some small code to play. In the original code all sums are stored in an array and used later. Therefore printf is only a solution for the small debug code.
You need the round. The effect is much more seldom when using *100, but still exists. Please see:
my @nr=('34455.28','-33907.55');
my $x=0;
foreach (@nr)
{ $x+=($_*100);
print "$_ => ".$x/100 ."\n";
}
34455.28 => 34455.28
-33907.55 => 547.729999999995
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|