How can I cast Long
to BigDecimal
?
math. BigDecimal. valueOf(double val) is an inbuilt method in java that translates a double into a BigDecimal, using the double's canonical string representation provided by the Double. toString(double) method.
This method returns a BigDecimal whose value is the absolute value of this BigDecimal and whose scale is this. scale(). This method returns a BigDecimal whose value is (this + augend) and whose scale is max(this. scale(), augend.
According to my own benchmarking for my specific use case it's 10 - 20x slower than double (much better than 1000x) - basically for addition / multiplication.
You'll have to create a new BigDecimal
.
BigDecimal d = new BigDecimal(long);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With