1

I want to generate table with float data type similar to this decimal table.

add_column :table_name, :lat, :decimal, {:precision=>10, :scale=>6}

How do I do that properly ? And what would terminal command look like for rails generate model

Kunok
  • 8,089
  • 8
  • 48
  • 89

2 Answers2

2

The correct is 'price:decimal{5,2}' or price:decimal{5-2}

rails generate migration AddDetailsToProducts 'price:decimal{5,2}'

as pointed out here

0

Decimal is better than Float.

You can find why here: https://en.wikipedia.org/wiki/IEEE_floating_point

And in this other SO post:

Float vs Decimal in ActiveRecord

So for me.. your first approach is correct. Use decimal with precision.

BTW i think rails does not support :float with :precision.

Community
  • 1
  • 1