Search code examples
javatype-conversionbigdecimal

Convert int to BigDecimal with decimal - Java


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.


Solution

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

    BigDecimal.valueOf(i).movePointLeft(2)
    

    does what you want.