How do I check that a number is float or integer?

前端 未结 30 2636
栀梦
栀梦 2020-11-22 00:01

How to find that a number is float or integer?

1.25 --> float  
1 --> integer  
0 --> integer  
0.25 --> float
<         


        
30条回答
  •  自闭症患者
    2020-11-22 00:53

    It really depends on what you want to achieve. If you want to "emulate" strongly typed languages then I suggest you not trying. As others mentioned all numbers have the same representation (the same type).

    Using something like Claudiu provided:

    isInteger( 1.0 ) -> true

    which looks fine for common sense, but in something like C you would get false

提交回复
热议问题