[Solved] How to convert Money to BigDecimal in Java? [closed]


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.

solved How to convert Money to BigDecimal in Java? [closed]