I have a problem with BigDecimal.
This code:
x = BigDecimal.new('1.0') / 7
puts x.to_s
outputs:
0.142857142857142857E0
I want to increase the number of digits.
In JAVA, I could do:
BigDecimal n = new BigDecimal("1");
BigDecimal d = new BigDecimal("7");
n = n.divide(d,200, RoundingMode.HALF_UP);
System.out.println(n);
Conclusion:
0.1428571428571428571428571428571428571428571428571428571428... (200 digits)
I looked at the BigDecimal documentation and tried to set the digits when creating the number instance, and then tried to set the limit using BigDecimal.limit, but I could not print more than 18 digits.
What am I missing?
I am running ruby 1.9.3p0 (2011-10-30) [i386-mingw32] on Windows 7 64bits
source
share