Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Strange int() result

by Athanasius (Monsignor)
on Jun 18, 2014 at 09:30 UTC ( #1090280=note: print w/ replies, xml ) Need Help??


in reply to Strange int() result

The simplest way to round to a whole number is to add 0.5 before truncating with int:

19:26 >perl -wE "say int(35784.45 * 100); say int(35784.45 * 100 + 0.5 +);" 3578444 3578445 19:27 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Strange int() result
Download Code
Re^2: Strange int() result
by hexcoder (Hermit) on Jun 18, 2014 at 21:18 UTC
    ... and for negative values subtract 0.5
    perl -wE "say int(-35784.45 * 100 - 0.5);" -3578445

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-24 00:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (243 votes), past polls