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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using (s)printf()
by Anonymous Monk on Oct 01, 2012 at 11:04 UTC | |
by Anonymous Monk on Oct 01, 2012 at 11:11 UTC | |
by Anonymous Monk on Oct 03, 2012 at 06:14 UTC |