For when you need that little bit of extra accuracy, specifying precision and scale for a decimal column in your Ruby on Rails migration is pretty simple. The precision represents the total number of digits in the number, whereas scale represents the number of digits following the decimal point. To specify the precision and scale, simply pass those as options to your column definition.
For example:
This will allow you to have 10 digits after the decimal point and 15 digits max.
One thing to note, however is that Rails will use BigDecimal as the type for the column. BigDecimal provides support for very large or very accurate floating point numbers. Remember those pesky floating point imprecision errors?
Yep, BigDecimal handles that…
So now, go forth and be accurate.
Also see
Need web application development, maintenance for your existing app, or a third party code review?
Velocity Labs can help.
Hire us!