简体   繁体   English

在Rails中处理红宝石中的许多小数点

[英]dealing with many decimal points in ruby on rails

Im currently getting this result for multiplication 我目前正在将此结果用于乘法

(0.01317818 * 0.00014300) 
=> 1.88447974e-06

How can I make the returned result 我怎样才能得到返回的结果

(0.01317818 * 0.00014300) 
=> 0.00000188

Across the whole system 整个系统

You can use bigdecimal . 您可以使用bigdecimal It is a gem . 这是一颗gem

require 'bigdecimal'

a = BigDecimal.new('0.01317818')
b = BigDecimal.new('0.00014300')
c = a * b

To get 8 decimal places: 要获得8位小数:

"%.8f" % (0.01317818 * 0.00014300)
=> 0.00000188

A bit simpler than using big decimal. 比使用大十进制要简单一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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