Sometimes I see code using to_d
. The ruby documentation even states there is a Float#to_d
method. However, it's not in my version of ruby (ruby 1.9.3p263 (2012-08-23 revision 36792
).
1.9.3p263 :001 > "0.0".to_d
NoMethodError: undefined method `to_d' for "0.0":String
from (irb):1
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
1.9.3p263 :002 > 0.0.to_d
NoMethodError: undefined method `to_d' for 0.0:Float
from (irb):2
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
1.9.3p263 :003 > 0.to_d
NoMethodError: undefined method `to_d' for 0:Fixnum
from (irb):3
from /home/iblue/.rvm/rubies/ruby-1.9.3-head/bin/irb:16:in `<main>'
No to_d
in Float
, String
or Fixnum
. What's going on?
As stated in the example of the documentation you need
require 'bigdecimal'
require 'bigdecimal/util'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With