ale
ale

Reputation: 11824

Converting BigDecimal ActiveRecord to Ruby string

I get a record from the DB like this:

@foo = Foo.find(params[:foo_id])

I need the whole @foo record but I need to use the value field in the ActiveRecord (of type BigDecimal). I think I can do this (?):

 @val = @foo.value

but how do I convert @val to a string? I found a to_str method but I get:

 undefined method `to_str' for #<BigDecimal:7f88d4e5fa10,'0.5155170589 999999E2',27(45)>

when I try and call to_str on @val like this:

 @val = @foo.value.to_str # ERROR here

Upvotes: 2

Views: 4025

Answers (1)

Mike Szyndel
Mike Szyndel

Reputation: 10593

You need to use to_s method which is standard method to convert any object to string in Ruby.

Upvotes: 2

Related Questions