2012-09-05 86 views
3

很抱歉,如果这是显而易见的,但我搜索谷歌,堆栈溢出和Ruby文档,我找不到它。红宝石十进制精度

我该如何去做更高精度的小数?例如,在IRB中,

irb(main):001:0> 3.14159265358979323846 
=> 3.141592653589793 

它切断了一些小数。我如何保留整个小数?

回答

1

试试这个:

require 'bigdecimal/math' 
include BigMath 
puts PI(70) #You'll get a few more digits above 70, but those will be off. 70 is by no means the maximum. 
#=> 0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862802532985155833326733E1