Home > Mobile >  Separate double to integer and first decimal part? [duplicate]
Separate double to integer and first decimal part? [duplicate]

Time:10-04

What is the most efficent way to separate a double like 45.556 to an integer 45 and a second integer 5 (the first decimal part, without rounding).

CodePudding user response:

Try this dude..

        double num=45.556;
        int a=(int)num;
        int b=(int)((num-a)*10);
        System.out.println(num " , " a " , " b);
45.556 , 45 , 5
  •  Tags:  
  • java
  • Related