Converting BigDecimal to Integer

后端 未结 8 1020
既然无缘
既然无缘 2020-12-04 14:43

I have Hibernate method which returns me a BigDecimal. I have another API method to which I need to pass that number but it accepts Integer as parameter. I cannot change ret

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 15:32

    You would call myBigDecimal.intValueExact() (or just intValue()) and it will even throw an exception if you would lose information. That returns an int but autoboxing takes care of that.

提交回复
热议问题