Java - Format number to print decimal portion only

后端 未结 3 1645
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 06:41

Is there a simple way in Java to format a decimal, float, double, etc to ONLY print the decimal portion of the number? I do not need the integer portion, even/especially if

3条回答
  •  北海茫月
    2020-12-19 07:19

    This will print 0.3

    double x = 23.8;
    int y =(int)x;
    float z= (float) (x % y);
    System.out.println(z);
    

提交回复
热议问题