3

How can I convert a large double, one that won't fit into the Long data type:

var ex = 10e28 : Double;
ex -= 0.25

to a BigInt? Also making sure to round to the nearest BigInt.

sungiant
  • 3,152
  • 5
  • 32
  • 49

1 Answers1

1

I'm assuming that by "nearest" you mean you want e.g. 10.49 rounded to 10, 10.5 rounded to 11, etc. If so you can write the following:

BigDecimal(ex).setScale(0, BigDecimal.RoundingMode.HALF_UP).toBigInt

See my answer here for more information about the rounding modes.

Community
  • 1
  • 1
Travis Brown
  • 138,631
  • 12
  • 375
  • 680