Java Double get all Digits after dot/comma


it´s a simple task but i´m not able to solve it on my own..

i got

    double digit1 = 12.1;    double digit2 = 12.99;

and need a method which gives me this:

    anyMethod(digit1); //returns 10    anyMethod(digit2); //returns 99

what i have is

public static void getAfterComma(double digit) {    BigDecimal bd = new BigDecimal(( digit - Math.floor( digit )) * 100 );    bd = bd.setScale(4,RoundingMode.HALF_DOWN);    System.out.println(bd.toBigInteger()); // prints digit1=1 and digit2=99} 

anyway i prefer integer as the returntype..
anybody got a quick solution/tip?


Best Solution

Why not you simply use:

int anyMethod(double a){  //if the number has two digits after the decimal point.  return (int)((a + 0.001) * 100) % 100;}