JavaScript 除法取整

JavaScript About 289 words

方法一

Math.floor

var a = 7;
var b = 3;
var quotient = Math.floor(a / b);
console.log(quotient);  // 输出 2

方法二

parseInt

var a = 7;
var b = 3;
var quotient = parseInt(a / b);
console.log(quotient);  // 输出 2

方法三

|0

var a = 7;
var b = 3;
var quotient = (a / b)|0;
console.log(quotient);  // 输出 2
Views: 563 · Posted: 2023-11-30

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh