Project

General

Profile

Bug #12548

Rounding modes inconsistency between round versus sprintf

Added by unclekiki (Kieran McCusker) over 4 years ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:76253]

Description

Hi

I've found this possible bug with sprintf in our production code, but it
seems very odd that no one has reported it so I'm doubting myself.

I've tested a few versions (CRuby 2.3.1 and 2.1.9) and it was present in
both.

To reproduce in irb:

sprintf('%1.0f', 12.5)

Expected result 13 actual 12

In fact if you look at the number sequence 0.5 -> 99.5 you find the even
half will all round down and the odd half round up. 12.5.round produces the correct result (13)

If you do the same in jruby 2.2.1 you get the expected result of 13.

Many thanks

Kieran


Files

round_even.patch (4.43 KB) round_even.patch noahgibbs (Noah Gibbs), 09/22/2016 04:40 AM

Related issues

Related to Ruby master - Bug #12958: Breaking change in how `#round` worksClosedmrkn (Kenta Murata)Actions

Also available in: Atom PDF