本篇內(nèi)容主要講解“js的math對象方法實例介紹”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“js的math對象方法實例介紹”吧!
成都創(chuàng)新互聯(lián)專注于紅山企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),成都做商城網(wǎng)站。紅山網(wǎng)站建設(shè)公司,為紅山等地區(qū)提供建站服務(wù)。全流程按需設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
Math對象方法
//返回最大值 var max=Math.max(95,93,90,94,98); console.log(max); //返回最小值 var min=Math.min(95,93,90,94,98); console.log(min); //向上取整 console.log(Math.ceil(2.2)); console.log(Math.ceil(-2.2)); //向下取整 console.log(Math.floor(2.2));//2 console.log(Math.floor(-2.2));//-3 //四折五入 console.log(Math.round(2.4));//四舍五入--3 console.log(Math.round(-2.5));//負數(shù)+0.5,向下取整 console.log(Math.round(-3.4));//-3 //隨機數(shù) var b=Math.random();//[0,1) var d=b*41//[0,41)所有數(shù) var e=d+10//[10,51)所有數(shù) var f=Math.floor(e)//[10,50]之間的整數(shù) //10到50的區(qū)間,包含10也包含50 var gongs=Math.floor(Math.random()*(50-10+1)+10); var num=-10; Math.abs(num);//10 Math.abs(10);//10 //返回 e 的 x 次冪的值。 console.log(Math.exp(4))//e //返回數(shù)的自然對數(shù)(底為e) console.log(Math.log(2)) //pow() 方法可返回 x 的 y 次冪的值 console.log(Math.pow(2,3))//8 //sqrt() 方法可返回一個數(shù)的平方根 console.log(Math.sqrt(2))// //關(guān)于隨機數(shù)的一個小練習 //每刷新一次字的顏色就要變化一次 var num2=9; console.log(num2.toString(16))//f,toString轉(zhuǎn)換成字符串 //一位【0,15】 var color="#";//用變量進行字符串拼接 for(var i=0;i<6;i++){//該循環(huán)循環(huán)6次,獲取16進制表示顏色的數(shù) var yi=Math.floor(Math.random()*16).toString(16); color=color+yi;//字符串拼接獲取一個完整的顏色的值 } console.log(color);//檢測16進制的顏色是否成功合成 document.write("<font color="+color+">我會變顏色</font>")//把顏色打印出來 //0-15
到此,相信大家對“js的math對象方法實例介紹”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
分享標題:js的math對象方法實例介紹
分享地址:http://muchs.cn/article46/gdsheg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、服務(wù)器托管、搜索引擎優(yōu)化、網(wǎng)站導(dǎo)航、定制網(wǎng)站、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)