1

I am using Ruby 2.2.4 and PostgreSQL. I have created migration:

add_column :plans, :price, :decimal, precision: 7, scale: 2

When I am going to create new record, it will save value in price column with only one precision.

Why it happens? I want value with 2 precisions.

Ex: Current value which is save: 20.0 I want: 20.00

unnati patil
  • 1,601
  • 2
  • 13
  • 12
  • 1
    it shows you 20.0 it does not save it any special way. or it can show you 20.00, but again it does not matter it save it in special way. float value of 20.0 and 20.00 is same. so look at displaying differently, not saving. btw I'm talking for Postgres only – Vao Tsun Jun 24 '16 at 10:26

2 Answers2

0
select round(20.0 , 2), 20.00::double precision, 20.00::numeric

enter image description here

so you can use round() for fixed number of digits after the dot

Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
0

I have used number_to_currency(@price). It is a method of ActionView::Helpers::NumberHelper

unnati patil
  • 1,601
  • 2
  • 13
  • 12