Alex Rivera | Logout

Converting BigDecimal to Integer

Asked 2010-10-28T13:56:52.003
146

I have a Hibernate method which returns a BigDecimal.

I have another API method to which I need to pass that number but it accepts Integer as the parameter. I cannot change return types or variable types of either method.

How to convert the BigDecimal into an Integer and pass it to the second method?

Edit
Report

2 Answers

9

Following should do the trick:

BigDecimal d = new BigDecimal(10);
int i = d.intValue();
answered 2010-10-28T14:00:06.973
1

Have you tried calling BigInteger#intValue() ?

answered 2010-10-28T14:02:17.890

Your Answer