Skip to content


Rails Migrations: Decimal, Precision, and Scale

I have a tough time remembering which is which…

Precision is the total number of digits, scale is the number digits after the decimal point.

For example:

t.decimal :tax_percent, :precision => 6, :scale => 4

Would give you a total of six digits, with 4 after the decimal point.

Posted in Rails, Ruby, Tips and Tricks.

Tagged with , , , , , , .


7 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. skiz says

    I have a hard time remembering these options, and I always end up here. Thanks 🙂

  2. nitindhar7 says

    I always mix these two up .. thanks for reminding!

  3. Tom says

    Are there default values for precision and scale?

  4. jtanium says

    I believe if you don’t specify the values then the database’s defaults are used, in the case of MySQL, which is DECIMAL(10,0), where 10 is the precision and 0 is the scale.

    I haven’t tested this though…

  5. Jeyant says

    Thanks. The post was very helpful.

  6. Nowaker says

    Not sure if this works on SQLite. After a few months, 29.995 appeared in a column defined as :precision => 8, :scale =>2.

  7. saravanan says

    thanks man



Some HTML is OK

or, reply to this post via trackback.