Project

General

Profile

Actions

Bug #12780

closed

BigDecimal#round returns different types depending on argument

Added by Gat (Dawid Janczak) over 7 years ago. Updated over 3 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-09-21 trunk 56199) [x86_64-linux]
[ruby-core:77333]
Tags:

Description

BigDecimal#round returns Integer when no arguments are given and BigDecimal otherwise. I would have assumed the result to always be BigDecimal.

BigDecimal.new('12.34').round # => 12 (Integer)
BigDecimal.new('12.34').round(0) # => 12 (BigDecimal)

Attached is a patch with possible fix.

I found a similar issue to this one (https://bugs.ruby-lang.org/issues/2662), but it's in Japanese. If this should be rejected as well could someone provide an explanation in English please? Also in that case documentation should be changed as it clearly states that the result should be BigDecimal: "Round to the nearest integer (by default), returning the result as a BigDecimal."


Files

bigdecimal_round.diff (969 Bytes) bigdecimal_round.diff Gat (Dawid Janczak), 09/21/2016 10:47 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #13420: Integer#{round,floor,ceil,truncate} should always return an integer, not a floatClosedstomar (Marcus Stollsteimer)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0