in reply to Problems with pack-ing data.
Output:#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; my @v = map $_ * 100, 160.22, 160.23; printf "%.20f %d\n", $_, int for @v;
16022.00000000000000000000 16022 16022.99999999999818101060 16022
See the popular article What Every Programmer Should Know About Floating-Point Arithmetic.
Update: Try the following to see the correct number, too:
See also round or lround in POSIX.printf "%.20f %.0f %d\n", $_, $_, int for @v;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problems with pack-ing data.
by seann (Novice) on Apr 26, 2021 at 18:18 UTC | |
by BillKSmith (Monsignor) on Apr 27, 2021 at 13:31 UTC |