Results 1 to 3 of 3
  1. #1
    doymand is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default Using BigDecimal

    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.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Destiny Islands
    Rep Power


    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.

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Zurich, Switzerland
    Rep Power


    look at the methods of the class BigDecimal here to find out which operations the class offers. and for formatting numbers you can use the class NumberFormat specified and explained here

Similar Threads

  1. How do i Multiply a BigDecimal by a Double
    By s0meb0dy in forum New To Java
    Replies: 33
    Last Post: 09-26-2010, 01:05 AM
  2. BigDecimal question
    By orchid in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:44 PM
  3. convert a really big string (len 39) to bigdecimal
    By coolsig in forum Advanced Java
    Replies: 6
    Last Post: 06-14-2008, 02:48 AM
  4. BigDecimal - Help formulating if statments
    By shinjitsunohana in forum New To Java
    Replies: 5
    Last Post: 04-28-2008, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts