Project

General

Profile

Bug #13062 ยป fix_13062_string_to_d.patch

Esse (Piotr Szmielew), 12/25/2016 12:16 AM

View differences:

ext/bigdecimal/lib/bigdecimal/util.rb
58 58
  #     # => 0.5e0
59 59
  #
60 60
  def to_d
61
    BigDecimal(self)
61
    begin
62
      BigDecimal(self)
63
    rescue ArgumentError
64
      BigDecimal(0)
65
    end
62 66
  end
63 67
end
64 68

  
test/bigdecimal/test_bigdecimal_util.rb
48 48
  def test_Rational_to_d_with_negative_precision
49 49
    assert_raise(ArgumentError) { 355.quo(113).to_d(-42) }
50 50
  end
51

  
52
  def test_String_to_d
53
    assert_equal("2.5".to_d, BigDecimal.new('2.5'))
54
  end
55

  
56
  def test_invalid_String_to_d
57
    assert_equal("invalid".to_d, BigDecimal.new('0.0'))
58
  end
59

  
51 60
end
52
-