V
Vincent Arnoux
Hello,
I am trying to calculate pi in an arithmetical way with a big number of
decimal digits.
Unfortunately, the code below only displays 15 digits. How can I ask for
more digits ?
require 'bigdecimal'
puts("Enter precision : ")
precision = gets.chomp.to_i
i, sign = 1.0, 1
value = BigDecimal.new("0")
pi = BigDecimal.new("0")
precision.times do
value += 1/i * sign
sign *= -1
i += 2
end
pi = 4 * value
puts pi.to_s
Vincent
I am trying to calculate pi in an arithmetical way with a big number of
decimal digits.
Unfortunately, the code below only displays 15 digits. How can I ask for
more digits ?
require 'bigdecimal'
puts("Enter precision : ")
precision = gets.chomp.to_i
i, sign = 1.0, 1
value = BigDecimal.new("0")
pi = BigDecimal.new("0")
precision.times do
value += 1/i * sign
sign *= -1
i += 2
end
pi = 4 * value
puts pi.to_s
Vincent