Issue #13138 has been updated by Nobuyoshi Nakada.


Fixed by r55604 in the trunk.

```diff
diff --git i/numeric.c w/numeric.c
index 46f112349f..9ff68f25c9 100644
--- i/numeric.c
+++ w/numeric.c
@@ -1786,7 +1786,7 @@ static VALUE
 flo_round(int argc, VALUE *argv, VALUE num)
 {
     VALUE nd;
-    double number, f;
+    double number, f, x;
     int ndigits = 0;
     int binexp;
     enum {float_dig = DBL_DIG+2};
@@ -1828,7 +1828,14 @@ flo_round(int argc, VALUE *argv, VALUE num)
 	return DBL2NUM(0);
     }
     f = pow(10, ndigits);
-    return DBL2NUM(round(number * f) / f);
+    x = round(number * f);
+    if (x > 0) {
+	if ((x + 0.5) / f <= number) x += 1;
+    }
+    else {
+	if ((x - 0.5) / f >= number) x -= 1;
+    }
+    return DBL2NUM(x / f);
 }
 
 /*
diff --git i/test/ruby/test_float.rb w/test/ruby/test_float.rb
index 3afd26d0b4..7d979a824f 100644
--- i/test/ruby/test_float.rb
+++ w/test/ruby/test_float.rb
@@ -442,6 +442,11 @@
     assert_raise(TypeError) {1.0.round(nil)}
     def (prec = Object.new).to_int; 2; end
     assert_equal(1.0, 0.998.round(prec))
+
+    assert_equal(+5.02, +5.015.round(2))
+    assert_equal(-5.02, -5.015.round(2))
+    assert_equal(+1.26, +1.255.round(2))
+    assert_equal(-1.26, -1.255.round(2))
   end
 
   VS = [
```

----------------------------------------
Bug #13138: Rounding bug 
https://bugs.ruby-lang.org/issues/13138#change-62561

* Author: Roma Shukla
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
31.175.round(2) = 31.18
32.175.round(2) = 32.17 (I expect 32.18)


---Files--------------------------------
round.png (5.82 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>