Mega Code Archive

 
Categories / Ruby / Number
 

Calculation on BigDecimal in a function

require 'bigdecimal' def two_thirds(precision)   (BigDecimal("2", precision) / BigDecimal("3")).to_s end two_thirds(1)                           # => "0.6666666666666667E0" two_thirds(4)                           # => "0.6666666666666667E0" two_thirds(5)                           # => "0.66666666666666666667E0" two_thirds(9)                           # => "0.666666666666666666666667E0" two_thirds(13)                          # => "0.6666666666666666666666666667E0"