in reply to shocking imprecision

If you want int to round-off, just add 0.5 before taking the integer part.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: shocking imprecision
by Ovid (Cardinal) on Oct 18, 2011 at 05:32 UTC

    Actually, that's why sprintf and printf are recommended:

    perl -E 'say int(-1.2 + .5); printf("%d\n",-1.2)'

    One of those is going to send the Monk back here with more questions :)