Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2022-08-08 04:41 GMT
Find Nodes?
    Voting Booth?

    No recent polls found