Hello Rubies,
Accurately convert numbers to decimal or exact precision point. Use the Flt gem do discover the below scenario.
Flt::DecNum is a standards-compliant
arbitrary precision decimal floating-point type for Ruby. It is based on
the Python Decimal class.
Usage:
sudo gem install flt
require 'flt'
include Flt
x = 0.00000020586
y = Flt::DecNum(x.to_s)
Flt::DecNum.context.precision = 2
puts y/Flt::DecNum(1)
result should be 2.1E-7
For more information just follow the http://flt.rubyforge.org/.
No comments:
Post a Comment