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

Re: Multiply with 100 in perl

by ctilmes (Vicar)
on Nov 11, 2015 at 20:47 UTC ( #1147498=note: print w/replies, xml ) Need Help??


in reply to Multiply with 100 in perl

This won't fix your immediate problem (others have pointed out why it happens), but to give you hope for the future, this is one of many things perl6 gets right. It does math right.(tm)
$ perl6 -e 'printf "%d\n", 75.600 * 100' 7560

Replies are listed 'Best First'.
Re^2: Multiply with 100 in perl
by grasshopper!!! (Beadle) on Nov 12, 2015 at 00:37 UTC

    Floating point arithmetic has limited accuracy try bignum library.

    perl -Mbignum -e 'printf"%.20F\n", 75.600 * 100;'

      Bignum is good, but printf still converts to float.

      $ perl -Mbignum -e 'printf "%.32g\n", 75.600 * 10**30' 75599999999999995986368094273536 $ perl -Mbignum -le 'print 75.600 * 10**30' 75600000000000000000000000000000

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2021-09-27 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?