Finding the golden ratio accurately till 20 decimal places
calculator, decimal, java
Solution
java.math.BigDecimal is your way to go
BigDecimal.ONE.add(new BigDecimal(Math.sqrt(5))).divide(new BigDecimal(2))
represents the formula that you had posted and will return 1.6180339887498949025257388711906969547271728515625
That is, till 49 decimal places
Problem
Golden ratio is a special ratio which can be related to ratio between different dimensions of parts of a living organism. Mathematically, it can be found by the following formula : (1+sq.root(5))/2) By using any kind of data-type I couldn't store such a value. `double` is the best, but I can't get 20 decimal places using it. So, I thought, if I can find the last digits of the ratio after calculating it, and then store it in some variable and go on doing this. In the end I could have made it complete by joining the decimal places one after the other. example : from 1.61083, I would extract 3,0,8,0,1,6 and join it. Still I'm having problems since even during calculation it does not use such an accurate variable. Can somebody help ?