Search code examples
ruby-on-railsrubyruby-on-rails-4

Remove . from decimal ruby


I have a decimal column price. I got two prices: 10.00 and 11.50

I need to transform

10.00 into 1000

11.50into 1150

How I can do that in controller?


Solution

  • Just multiply the number by 100 and then do to_i on the result:

    f = 10.0
    n = (f * 100).to_i