Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cast Long to BigDecimal

How can I cast Long to BigDecimal?

like image 828
Suresh Avatar asked May 28 '09 15:05

Suresh


People also ask

How do you give value 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.

How do I return to BigDecimal?

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.

How much slower is BigDecimal than double?

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.


1 Answers

You'll have to create a new BigDecimal.

BigDecimal d = new BigDecimal(long); 
like image 77
Silfverstrom Avatar answered Oct 03 '22 03:10

Silfverstrom