js中Math之random,round,ceil,floor的用法總結_javascript技巧
來源:懂視網
責編:小采
時間:2020-11-27 21:17:51
js中Math之random,round,ceil,floor的用法總結_javascript技巧
js中Math之random,round,ceil,floor的用法總結_javascript技巧:1.Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) [html] view plaincopyprint 2.Math.floor(num); 參數num為一個數值,函數結果為num的整數部分(返回小于等于n的最大整數
導讀js中Math之random,round,ceil,floor的用法總結_javascript技巧:1.Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) [html] view plaincopyprint 2.Math.floor(num); 參數num為一個數值,函數結果為num的整數部分(返回小于等于n的最大整數

1.Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1)
Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) [html] view plaincopyprint?
2.Math.floor(num); 參數num為一個數值,函數結果為num的整數部分(返回小于等于n的最大整數)。
Math.floor(num); 參數num為一個數值,函數結果為num的整數部分(返回小于等于n的最大整數)。[html] view plaincopyprint?
3.Math.round(num); 參數num為一個數值,函數結果為num四舍五入后的整數。
Math.round(num); 參數num為一個數值,函數結果為num四舍五入后的整數。[html] view plaincopyprint?
4.Math.ceil(n); 返回大于等于n的最小整數。
Math.ceil(n); 返回大于等于n的最小整數。[html] view plaincopyprint?
5.Math.ceil(Math.random()*10);時,主要獲取1到10的隨機整數,取0的幾率極小。
Math.ceil(Math.random()*10);時,主要獲取1到10的隨機整數,取0的幾率極小。[html] view plaincopyprint?
6.Math.round(Math.random());可均衡獲取0到1的隨機整數。
Math.round(Math.random());可均衡獲取0到1的隨機整數。[html] view plaincopyprint?
7.Math.round(Math.random()*10);時,可基本均衡獲取0到10的隨機整數,其中獲取最小值0和最大值10的幾率少一半。
Math.round(Math.random()*10);時,可基本均衡獲取0到10的隨機整數,其中獲取最小值0和最大值10的幾率少一半。[html] view plaincopyprint?
8.Math.floor(Math.random()*10);時,可均衡獲取0到9的隨機整數。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
js中Math之random,round,ceil,floor的用法總結_javascript技巧
js中Math之random,round,ceil,floor的用法總結_javascript技巧:1.Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) Math.random(); 結果為0-1間的一個隨機數(包括0,不包括1) [html] view plaincopyprint 2.Math.floor(num); 參數num為一個數值,函數結果為num的整數部分(返回小于等于n的最大整數