Check if a number is a double or an int

后端 未结 5 2081
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 11:49

I am trying to beautify a program by displaying 1.2 if it is 1.2 and 1 if it is 1 problem is I have stored the numbers into the arraylist as doubles. How can I check if a Number

5条回答
  •  遇见更好的自我
    2021-02-06 12:23

    Alternatively one can use this method too, I found it helpful.

    double a = 1.99; 
    System.out.println(Math.floor(a) == Math.ceil(a));
    
    

提交回复
热议问题