I have a quicky since I already figured it out.

So I was messing with my database when I realized that all the fields that I had given a type of decimal didn't actually give me decimal level precision. Everything was all whole numbers. As it turns out that by default when you do a migration like this


def self.up
create_table :foo do |t|
t.column "bar", :decimal
end
end


There is an inherent precision of 10 and a scale of 0. What this means is that you can only do whole numbers. As it turns out precision stands for the total number of numerical charactors that field will store total and the scale is the number of numberical charecters the field will store after the decimal point. So for example a decimal with a precision of 8 and a scale of 2 will store numbers like this 123456.78 or 123.46(rounded up) This also means that the precision must always be greater than or equal to the scale.

Here is an example of how to set the precision and scale of a decimal type field manually.


def self.up
create_table :foo do |t|
t.column "bar", :decimal, :precision => 10, :scale => 6
end
end


Hope this helps.
Best Luck

One Response so far.

  1. Unknown says:

    The casino gambling 'no deposit bonus' (with bonuses)
    In a post published 네임드 파워 사다리 in the British gaming blog 샤오미 토토 Gamstop, we cover a 토토 와이즈 number of different types of casino 오즈포탈 games 실시간 바카라 사이트 and the casino bonus.

Leave a Reply