-2

I want to divide two large integers,

a = 23546654
b = 24979799

and to get the result in double.

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
DevAndroid
  • 99
  • 3
  • 7

3 Answers3

3

Try

double x = ((double) a) / ((double) b)

which first converts your ints to doubles and then does the division. If you have BigIntegers (which your tag indicates) you may use BigInteger.doubleValue() to extract the double value.

Howard
  • 38,639
  • 9
  • 64
  • 83
1

BigInteger class has a divide method.

BigInteger result = a.divide(b);
codeling
  • 11,056
  • 4
  • 42
  • 71
Abhishek bhutra
  • 1,400
  • 1
  • 11
  • 29
  • 1
    Even better would be divideAndRemainder method which will help the OP to get a double/floating point number. http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html#divideAndRemainder%28java.math.BigInteger%29 – Thomas Clayson Jan 04 '12 at 13:27
1

This are plain int rather than BigInteger.

All you need is

double ratio = (double) a / b;
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130