I am using a legacy database with mysql.
I am working stuff through in the console and it tells me...
@price = Price.find(:first, :conditions => ["stockid = ? AND typeabbrev
= ?", @test, "WH"]).price
=> #<Price price: #<BigDecimal:b7a7341c,'0.115E1',8(12)>>
So I need to coerce this into a float...
I added to app/controllers/application_controller.rb (at the very bottom
of the file)...
# Provides extension to Numerics to provide subject decimal places
class Float
def to_fl(digits)
sprintf("%.#{digits}f",self)
end
end
which used to work fine for me in Rails 1.2.6...but in the 2.3.2
console...
>> @price.to_i
=> 1
>> @price.to_fl(2)
NoMethodError: undefined method `to_fl' for
#<BigDecimal:b794c0fc,'0.115E1',8(12)>
from (irb):30
from :0
How do I get the float value of 'big decimal' ?
Craig
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---