Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Float#to_d?

Tags:

ruby

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?

like image 941
iblue Avatar asked Sep 04 '12 13:09

iblue


1 Answers

As stated in the example of the documentation you need

require 'bigdecimal'
require 'bigdecimal/util'
like image 170
Marcel Jackwerth Avatar answered Sep 19 '22 14:09

Marcel Jackwerth