Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: While loop with addition goes weird

by Laurent_R (Canon)
on Apr 08, 2018 at 14:30 UTC ( [id://1212539]=note: print w/replies, xml ) Need Help??


in reply to While loop with addition goes weird

Computers are notoriously bad at computing with decimal numbers. That includes most programming languages.

If you want accurate arithmetic, you might want to try using Perl 6:

> my $size = 0.01; 0.01 > my $step_size = 0.01; 0.01 > $size += $step_size while $size < 5; Nil > say "FINAL: $size"; FINAL: 5
;-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found