Project

General

Profile

Bug #17032

BigDecimal's `to_d` behaves inconsistent compared to `to_f`

Added by TiloS (Tilo S) 2 months ago. Updated 2 months ago.

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

Description

I would expect to_f and to_d to behave identically. Specifically, nil.to_d should behave like nil.to_f.

require 'bigdecimal'
require 'bigdecimal/util'
nil.to_f # => 0.0
nil.to_d # >> NoMethodError (undefined method `to_d' for nil:NilClass)

Users should not have to resort to this:

nil.to_f.to_d #  => 0.0

Also available in: Atom PDF