Gerry Jenkins wrote: > Gerry Jenkins wrote: >> Rimantas Liubertas wrote: >>>> note the inconsistent rounding. >>>> >>>> -1.05 rounds to -1.1 >>>> and >>>> -32.50 rounds to -32.0 >>>> >>>> from sprintf >>> >>> >>> For me it looks like you are rounding -32.05, not -32.50. >>> >>>> irb(main):003:0> sprintf("%.1f",-32.05) >>> >>> >>> Regards, Rimantas >> >> Yes, I intend to round -32.05 to the nearest 1 decimal place not to a >> whole number. sprintf is suppose to round to the precision you specify. > > OK also inconsistent: > > irb(main):007:0> sprintf("%.0f",-1.5) > => "-2" > irb(main):008:0> sprintf("%.0f",-10.5) > => "-10" > > -1.5 rounds down to -2 > -10.5 rounds up to -10 fails even positive numbers: sprintf("%.0f",10.5) => "10" irb(main):013:0> sprintf("%.0f",11.5) => "12" -- Posted via http://www.ruby-forum.com/.