Wednesday, October 27, 2010

Convert double to int

double myDouble = 2.55;
System.out.println("double value=" + myDouble);

BigDecimal bd1 = new BigDecimal(Double.toString(myDouble));
BigDecimal bd2 = new BigDecimal(100);

bd1= bd1.multiply(bd2);
int i = bd1.toBigInteger().intValue();
System.out.println("Int value=" + myDouble);

No comments: