0

I have a decimal field that does not stores decimals, although the schema file says:

t.decimal  "kg", :precision => 10, :scale => 6

If I do:

(15,000 * 1,010)/1,000,000 

which should be 15.15

it will only show 15.00

On DDBB:

BigDecimal:7fd4cc707300,'0.15E2',9(36)
0

1 Answer 1

1

The result you're getting which I believe is 15 and not 15.15 is the way Fixnum division works. If you want decimals in your result, you need to include decimals in your operands:

Example:

# Decimal on denominator
> (15000 * 1010)/1000000.0
=> 15.15

# or, on numerator
> (15000.0 * 1010)/1000000
=> 15.15

You could then use this value to store in your kg field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.