Results 1 to 3 of 3
Thread: Using BigDecimal
- 10-30-2010, 06:39 AM #1Member
- Join Date
- Oct 2010
- Rep Power
I'm trying to make a program that will add the sum of an infinite geometric series(1 + 1/2 + 1/4 + 1/8....)
for (count; count<= limit; count++)
a = ((1)/(math.pow(2,count));
b += a;
This is easy to do when "b" and "a" are doubles, but they do not provide a high enough precision, I want to use BigDecimal to many decimal places, but I am having trouble doing it.
How do you show how many decimal points you want when creating the BigDecimal variable, and then add them together to get an answer?
How would I go about it? I know i'l just get more .9's and know that it's equal to two, but I would still like to know how to do it.
- 10-30-2010, 07:07 AM #2
What do you mean how many decimal points you want? BigDecimal goes to infinite precision until your computer runs out of memory.
You could literally have 0.9 followed by a googol 9s if your computer was powerful enough.
- 10-30-2010, 10:25 AM #3
- By s0meb0dy in forum New To JavaReplies: 33Last Post: 09-26-2010, 02:05 AM
- By orchid in forum New To JavaReplies: 2Last Post: 08-12-2008, 02:44 PM
- By coolsig in forum Advanced JavaReplies: 6Last Post: 06-14-2008, 03:48 AM
- By shinjitsunohana in forum New To JavaReplies: 5Last Post: 04-28-2008, 11:12 AM