in reply to Re^2: Problems with number resolution
in thread Problems with number resolution
Another point is that I don't see any reason to print incremental results each time through the look (except possibly for debugging purposes). Put the print statement after the end of the foreach loop.
And you might want to use printf instead of print in this specific case. In fact, using printf might be the only change that you need in your original code, as shown with this example under the Perl debugger:
DB<1> @nr=('32431.19', '20', '-10', '-31800'); DB<2> $x=0; DB<3> $x += $_ for @nr; DB<4> print $x 641.189999999999 DB<5> printf '%.2f', $x; 641.19
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Problems with number resolution
by Anonymous Monk on Jan 02, 2018 at 06:57 UTC | |
by Laurent_R (Canon) on Jan 02, 2018 at 08:42 UTC |