[英]Ruby BigDecimal multiplication
I'm in trouble with Bigdecimal multiplication. 我在使用Bigdecimal乘法时遇到麻烦。 I have a column:
我有一列:
t.decimal "average_price", precision: 8, scale: 2
My sample average_price
looks like "3.59280368"
. 我的样本
average_price
看起来像"3.59280368"
。 When I'm try to make some calculations with this value, I get: 当我尝试使用此值进行一些计算时,我得到:
@itam.average_price * 1000000 = 3590000
Why not 3592803
? 为什么不
3592803
?
According the the rails api documentation : 根据rails api文档 :
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
. 因此,在数据库中:
3.59280368
将存储为3.59
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.