Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Using (s)printf()

by Anonymous Monk
on Aug 01, 2012 at 16:59 UTC ( #984833=note: print w/ replies, xml ) Need Help??

in reply to Using (s)printf()

Your statement and example under "Rounding Numbers with sprintf()" is incorrect and misleading. Using "%d" does NOT round a float as necessary, it merely truncates everything after the decimal. Thus, printf("%d", 3.99); # will print 3, not 4.

# To properly 'round a float as necessary': printf("%.0f", 3.49); # This will print 3 printf("%.0f", 3.51); # This will print 4

Comment on Re: Using (s)printf()
Select or Download Code
Replies are listed 'Best First'.
Re^2: Using (s)printf()
by Anonymous Monk on Oct 01, 2012 at 11:04 UTC

    Perl exhibits strange behaviour after moving from x32 to x64 platform:


    # perl -e 'printf("%.2f", 6.685);' 6.68

    # perl -v This is perl, v5.10.1 (*) built for i386-linux-thread-multi


    # perl -e 'printf("%.2f", 6.685);' 6.69

    # perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

    Any changes in rounding algorithm?

        It looks like there is a problem with numeric.c: Perl_grok_number (Perl's own string-to-number conversion).

        Perl bugs tickets #115092, #41202

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2015-11-28 10:00 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls