Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Problems with number resolution

by haukex (Abbot)
on Jan 01, 2018 at 18:46 UTC ( #1206518=note: print w/replies, xml ) Need Help??

in reply to Problems with number resolution

davies has already linked you to What Every Programmer Should Know About Floating-Point Arithmetic, which is definitely worth reading, and poj has shown you one possible solution. Here are two more that give the desired output:

If you don't care about the inaccurate internal representation, use printf for output, as in: printf "%.2f => %.2f\n", $_, $x;

If you don't care so much about the performance of your program, stick a use bignum; at the top of your program (or at least in the lexical scope of the code you showed).

Replies are listed 'Best First'.
Re^2: Problems with number resolution
by Anonymous Monk on Jan 02, 2018 at 07:28 UTC

    Thanks haukex for your comment.

    Using "use bignum" is the solution what I was looking for.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1206518]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-07-17 23:14 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (379 votes). Check out past polls.