saadlulu
saadlulu

Reputation: 1395

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

Upvotes: 0

Views: 351

Answers (2)

MisterCal
MisterCal

Reputation: 622

To get 8 decimal places:

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

A bit simpler than using big decimal.

Upvotes: 1

Niladri Basu
Niladri Basu

Reputation: 10624

You can use bigdecimal. It is a gem.

require 'bigdecimal'

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

Upvotes: 1

Related Questions