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

Re: Floating point issue

by vitoco (Hermit)
on Aug 13, 2016 at 21:53 UTC ( [id://1169725]=note: print w/replies, xml ) Need Help??


in reply to Floating point issue

Thank you, guys.

I'll use sprintf as a workaround...

Replies are listed 'Best First'.
Re^2: Floating point issue
by Laurent_R (Canon) on Aug 14, 2016 at 08:14 UTC
    A more accurate alternative might be to use integer arithmetic:
    $ perl -E '$c = -71123456; for my $i (0..19) {say $c/1000000; $c += 10 +000}' -71.123456 -71.113456 -71.103456 -71.093456 -71.083456 -71.073456 -71.063456 -71.053456 -71.043456 -71.033456 -71.023456 -71.013456 -71.003456 -70.993456 -70.983456 -70.973456 -70.963456 -70.953456 -70.943456 -70.933456
    You might also consider using the arbitrary big rational number module (Math::BigRat) or possibly the big float module (Math::BigFloat).

    Math::BigRat is accurate because it basically does integer arithmetic under the hood.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1169725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found