If you specify that the ActiveRecord column type is decimal, Rails will return that database value as a Ruby BigDecimal object.
My question is that when working with these fields and doing extra math on them, I should always use BigDecimal values ββin my calculations or use floating point values ββin order. I did not know if it is good practice to mix BigDecimal values ββand Floating Point values ββin the same calculations.
Mixed example: BigDecimal.new ('12 .43 ') /4.2
Same type Example: BigDecimal.new ('12 .43 ') /BigDecimal.new (' 4.2 ')
The reason I'm asking for is because I'm a little scared using floats because I need decimal precision. 0.1 + 0.7 will not equal 0.8 using floats.
ruby-on-rails bigdecimal
Dale
source share