Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Math 101 anyone?

by Crian (Chaplain)
on Oct 13, 2004 at 09:23 UTC ( #398813=note: print w/ replies, xml ) Need Help??


in reply to Math 101 anyone?

I just tried out the behaviour of Perl in this case and found this:
perl -e "print 1/10"
gives the result 0.1

Also does
perl -e "print 1.0 / 10"
and
perl -e "print 1.0 / 10.0".

But
perl -e "print 100.1 - 100.0"
gives the well known 0.0999999999999943.

(All under ActiveStates Perl 5.8.0 under Windows 2000.)

Is there a special mechanism in Perl that "saves" the fraction? Or do I miss something else?


Comment on Re: Math 101 anyone?
Select or Download Code
Re^2: Math 101 anyone?
by BrowserUk (Pope) on Oct 13, 2004 at 09:28 UTC

    Try this:

    printf "%.32f\n", 1/10; 0.10000000000000001000000000000000

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-08-30 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls