js 運算的內建函式

2022-01-13 17:40:40 字數 1023 閱讀 7953

// 一、math.round()作用:四捨五入返回整數。(返回引數+0.5後,向下取整)

// math.round(5.57)  //返回6

// math.round(2.4)   //返回2

// math.round(-1.5)  //返回-1

// math.round(-5.8)  //返回-6

// 二、math.ceil()作用:返回大於等於引數的最小整數。

// math.ceil(5.57)  //返回6

// math.ceil(2.4)  //返回3

// math.ceil(-1.5)  //返回-1

// math.ceil(-5.8)  //返回-5

// 三、math.floor()作用:返回小於等於引數的最大整數。

// math.floor(5.57)  //返回5

// math.floor(2.4)  //返回2

// math.floor(-1.5)  //返回-2

// math.floor(-5.8)  //返回-6

// 四、parseint()作用:解析乙個字串,並返回乙個整數,這裡可以簡單理解成返回捨去引數的小數部分後的整數。

// parseint(5.57)  //返回5

// parseint(2.4)  //返回2

// parseint(-1.5)  //返回-1

// parseint(-5.8)  //返回-5

// 正數轉換和math.floor()一樣,負數不一樣

// 五、 math.random()

// 該方法可返回介於 0 ~ 1 之間的乙個隨機數

// 如果你希望生成任意值到任意值的隨機數,公式就是這樣的:

// // max - 期望的最大值, min - 期望的最小值

// parseint(math.random()*(max-min+1)+min,10);

// math.floor(math.random()*(max-min+1)+min);

內建運算函式

函式 abs a abs 15 print a 函式 divmod a divmod 5 2 print a 函式 pow a 5b 3c pow a,b,2 print c 函式 round a 0.1 0.2print a b round a,2 print b 函式 max a max 15,...

JS的內建函式reduce

js reduce函式,是ecmascript5規範中出現的陣列方法。在平時的工作中,相信大家使用的場景並不多,一般而言,可以通過reduce方法實現的邏輯都可以通過foreach方法來變相的實現,雖然不清楚瀏覽器的js引擎是如何在c 層面實現這兩個方法,但是可以肯定的是reduce方法肯定也存在陣...

js 系統內建函式

var str aaaa var atest new array ff er new array 10 new array ff fee var obj new obejct var today new date math物件示需要宣告。字串 length屬性 長度 concat方法 string ...