Viacheslav Gruzdov
Viacheslav Gruzdov

Reputation: 167

Ruby BigDecimal multiplication

I'm in trouble with Bigdecimal multiplication. I have a column:

t.decimal "average_price", precision: 8, scale: 2

My sample average_price looks like "3.59280368". When I'm try to make some calculations with this value, I get:

@itam.average_price * 1000000 = 3590000

Why not 3592803?

Upvotes: 2

Views: 451

Answers (1)

Mohammad Al Alwa
Mohammad Al Alwa

Reputation: 702

According the the rails api documentation:

The precision is the total number of significant digits and the scale is the number of digits that can be stored following the decimal point.

So, in the database: 3.59280368 will be stored as 3.59.

Upvotes: 5

Related Questions