This site requires JavaScript, please enable it in your browser!
Greenfoot back
Zamoht
Zamoht wrote ...

2012/7/4

More than 16 decimals.

Zamoht Zamoht

2012/7/4

#
I tried to calculate pi for fun, and my program is calculating fine, but I wonder if it's possible to get more than 16 decimals. I'm using the double datatype, and I know that there isn't any datatype that returns a higher amount of decimals or is there? Not what i know of, but there must be some way to get more than 16 decimals. Any ideas? Thanks for your time.
kiarocks kiarocks

2012/7/4

#
Look at this.
danpost danpost

2012/7/4

#
Or check out this discussion.
SPower SPower

2012/7/4

#
@danpost Thanks for the link: I didn't know the class BigDecimal exists, I wanted to write it myself :)
Zamoht Zamoht

2012/7/4

#
Thank you guys so much, though I still got one question. Which of the rounding modes is the most precise, there might not be "a most precise" rounding mode, but what would you use for calculating pi with more than 50 decimals? I found this on the API:
static int ROUND_CEILING Rounding mode to round towards positive infinity. static int ROUND_DOWN Rounding mode to round towards zero. static int ROUND_FLOOR Rounding mode to round towards negative infinity. static int ROUND_HALF_DOWN Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. static int ROUND_HALF_EVEN Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. static int ROUND_HALF_UP Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. static int ROUND_UNNECESSARY Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. static int ROUND_UP Rounding mode to round away from zero.
And here is my result.
You need to login to post a reply.