How do I convert a variable of type Money to type BigDecimal in Java?
BigDecimal big = BigDecimal.valueOf(money);
Doesn't work.
How do I convert a variable of type Money to type BigDecimal in Java?
BigDecimal big = BigDecimal.valueOf(money);
Doesn't work.
If Money
type is the one as suggested by Alexis C. in a comment above, from the Javadoc:
getAmount
java.math.BigDecimal getAmount()
Get the amount of money as a BigDecimal.
Returns: the BigDecimal amount
So you should just call BigDecimal big = money.getAmount();
Otherwise if Money
is a of a different type or your own custom class then to construct BigDecimal
representation you need to call the appropriate BigDecimal
constructor with the relevant money
amount.
Simple example:
// Assume getAmount() returns a numerical primitive type i.e. int, double, long
BigDecimal big = new BigDecimal(money.getAmount());
There are a lot of different constructors so please see the BigDecimal
javadoc.