Is there a generally accepted way to get Euler’s number in BigDecimal?
I basically want to do Math.exp(double a) and I basically want the same function but calculated using BigDecimal to prevent precision loss with other calculations.
I thought of just doing,
BigDecimal.valueOf(Math.E).pow(BigDecimal.SOMEOTHERNUMBER)
But not sure if that’s the right way to approach the problem.
The problem is that Euler’s number is irrational; in BigDecimal, you’d have to have infinite memory to hold it. The reason there’s no previously-stored value is that however many decimal places you needed, you wouldn’t have the right number for your current application.
You’re going to have to determine how many decimals you want, then construct the BigDecimal representation using the String constructor (new BigDecimal(“2.71828…”)).