Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bigdecimal/util.rb
Overview
bigdecimal/util extends the native String class to provide the #to_d method.
When you require ‘bigdecimal/util’ in your application, this method will be available on String objects.
Instance Method Summary collapse
-
#to_d ⇒ Object
call-seq: string.to_d -> bigdecimal.
Instance Method Details
#to_d ⇒ Object
call-seq:
string.to_d -> bigdecimal
Convert string to a BigDecimal and return it.
require 'bigdecimal'
require 'bigdecimal/util'
"0.5".to_d
# => 0.5e0
65 66 67 68 69 70 71 |
# File 'lib/bigdecimal/util.rb', line 65 def to_d begin BigDecimal(self) rescue ArgumentError BigDecimal(0) end end |