Ruby already has a built in solution:
0.33.rationalize.to_s # => "33/100" 0.4.rationalize.to_s # => "2/5" In Rails, ActiveRecord numerical attributes can be converted too:
product.size = 0.33 product.size.to_r.to_s # => "33/100" product.size = 0.33 product.size.to_r.to_s # => "33/100"