From: nobu@... Date: 2016-09-04T02:35:18+00:00 Subject: [ruby-core:77141] [Ruby trunk Bug#12718][Assigned] BigDecimal() should raise on invalid input, consistent with Integer() and Float() Issue #12718 has been updated by Nobuyoshi Nakada. Description updated Status changed from Open to Assigned Assignee set to Kenta Murata ---------------------------------------- Bug #12718: BigDecimal() should raise on invalid input, consistent with Integer() and Float() https://bugs.ruby-lang.org/issues/12718#change-60357 * Author: jonathan rochkind * Status: Assigned * Priority: Normal * Assignee: Kenta Murata * ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- ```ruby Integer("2") # => 2 Integer("invalid") # raises ArgumentError: invalid value for Integer() Float("2.0") # => 2.0 Float("invalid") # raises ArgumentError: invalid value for Float() ``` BUT ```ruby BigDecimal("2.2") # => # BigDecimal("invalid") # => # ``` I think `BigDecimal("invalid")` should raise rather than returning a `BigDecimal` representing `0`, to be consistent with `Integer()` and `Float()`, and to give you access to a string conversion that raises, which I don't think exists in stdlib at present. If you want conversion of a string to a `BigDecimal` that returns `0` rather than raising on bad input, you have String#to_d in `bigdecimal/util`. That's consistent with `String#to_f` and `#to_i` as well. But there is currently no way to do a conversion that raises, `BigDecimal()` is inconsistent with `Float()` and `Integer()` -- https://bugs.ruby-lang.org/ Unsubscribe: