6

BigDecimal was the choice to store numbers that have up to 5 digits after decimal point. I need to raise the BigDecimal to fractional power (up to 2 digits after decimal point). For example I have to bring 9.09671 to power of 1.51. Do I need some conversions from/to BigDecimal? How to do it?

EDIT: I cannot use 3rd party libraries as described in Java's BigDecimal.power(BigDecimal exponent): Is there a Java library that does it?

Is there more elegant, succint way for this case than described in How to do a fractional power on BigDecimal in Java?

Community
  • 1
  • 1
J.Olufsen
  • 13,415
  • 44
  • 120
  • 185
  • Could you explain why BigDecimal was chosen to represent the numbers? It may be, this choice was not optimal if operations like powering with a fraction are necessary. – Henry Jan 30 '15 at 18:59
  • I need to get precise result while doing subtraction, multiplication and bringing to power numbers that have up to 5 digits after decimal point. I cannot use any external libraries except provided with Java SE 5 . – J.Olufsen Jan 30 '15 at 19:02
  • Precise in what sense? Multiplying two numbers with 5 decimal places will in general have a result with 10 decimal places. – Henry Jan 30 '15 at 19:04
  • @Henry, Would You suggest to use `double` for this particular case? – J.Olufsen Jan 30 '15 at 19:10
  • Yes, unless your numbers have more than about 15 digits in total. – Henry Jan 30 '15 at 21:21

0 Answers0