7 Replies Latest reply: Jul 29, 2010 6:22 AM by 843789

# How to calculate percentage for two big integers?

How to calculate percentage for two big integers?

I am using BigInteger.divide method, but I am not getting accurate result. I need with fraction also.

Can any one help me on this.
• ###### 1. Re: How to calculate percentage for two big integers?
What have you done so far? What error's you getting?

James
• ###### 2. Re: How to calculate percentage for two big integers?
10/4 : means 2.5
For BigInteger.divide I am getting 2.

I need fraction value also.
• ###### 3. Re: How to calculate percentage for two big integers?
Integers give you whole numbers(2), not values (2.5)

Therefore you should look into doubles/floats etc.
• ###### 4. This Thread is now moved
Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.
• ###### 5. Re: How to calculate percentage for two big integers?
Read the documentation of BigInteger. It can only represent whole numbers.

If you want fractions, you'll have to use BigDecimal.
• ###### 6. Re: How to calculate percentage for two big integers?
javausers07 wrote:
10/4 : means 2.5
For BigInteger.divide I am getting 2.

I need fraction value also.
As said, that's the expected behavior of any kind of integer division.

Maybe you should be using BigDecimal ... or even, as suggested, doubles / floats.

db
• ###### 7. Re: How to calculate percentage for two big integers?
Thank you, Itried new BigDecimal(BigInteger)...its working.