Integers in JavaScript

后端 未结 5 2087
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 11:25

I\'m a beginner to Javascript so forgive me if I sound dumb because I learned some Javascript from W3Fools (which are really difficult tutorials - they don\'t explain anythi

5条回答
  •  天命终不由人
    2020-12-01 11:54

    Use this:

    function int(a) { return Math.floor(a); }
    

    And yo can use it like this:

    var result = int(2.1 + 8.7 + 9.3); //int(20.1)
    alert(result);                     //alerts 20
    

提交回复
热议问题