JavaScript - How To Detect Number As A Decimal (Including 1.0)

前端 未结 5 1285
梦毁少年i
梦毁少年i 2021-02-10 15:41

It feels like I am missing something obvious here. This has been asked a number of times - and the answer usually boils down to:

var num = 4.5;
num % 1 === 0; /         


        
5条回答
  •  醉酒成梦
    2021-02-10 16:23

    Let your script parse the input as string, then it will be a matter of checking if there is the point like this.

    mystring.indexOf('.');
    

    Check this example and this example.

提交回复
热议问题