Convert int to BigDecimal with decimal - Java

cakes88 picture cakes88 · Mar 2, 2016 · Viewed 62.4k times · Source

I'm having a hard time figuring out how to convert this. Here is what I want:

int i = 5900;

BigDecimal bD = new BigDecimal(i);

I need bD to be 59.00 but I can't figure out how to get this result. All I've been able to get is 5900 as type BigDecimal. Any suggestion would help, thanks.

Answer

Louis Wasserman picture Louis Wasserman · Mar 2, 2016

You haven't been very specific about the semantics you want, but it looks like

BigDecimal.valueOf(i).movePointLeft(2)

does what you want.