Checking if a number is an Integer in Java

后端 未结 11 540
生来不讨喜
生来不讨喜 2020-12-09 15:48

Is there any method or quick way to check whether a number is an Integer (belongs to Z field) in Java?

I thought of maybe subtracting it from the rounded number, but

11条回答
  •  攒了一身酷
    2020-12-09 16:30

    // in C language.. but the algo is same

    #include 
    
    int main(){
      float x = 77.6;
    
      if(x-(int) x>0)
        printf("True! it is float.");
      else
        printf("False! not float.");        
    
      return 0;
    }
    

提交回复
热议问题