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

前端 未结 5 1286
梦毁少年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:14

    Well, as far as the compiler is concerned, there is no difference between 1.0 and 1, and because there is no difference, it is impossible to tell the difference between them. You should change it from 1.0 to 100 for the the percentage thing. That might fix it.

提交回复
热议问题