简体   繁体   中英

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 ?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM