亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Javascript Math ceil()、floor()、round()三個(gè)函數(shù)的區(qū)別

 更新時(shí)間:2010年03月09日 20:57:26   投稿:mdxy-dxy  
Round是四舍五入的。。。Ceiling是向上取整。。float是向下取整

下面來介紹將小數(shù)值舍入為整數(shù)的幾個(gè)方法:Math.ceil()、Math.floor()和Math.round()。 這三個(gè)方法分別遵循下列舍入規(guī)則:
◎Math.ceil()執(zhí)行向上舍入,即它總是將數(shù)值向上舍入為最接近的整數(shù);
◎Math.floor()執(zhí)行向下舍入,即它總是將數(shù)值向下舍入為最接近的整數(shù);
◎Math.round()執(zhí)行標(biāo)準(zhǔn)舍入,即它總是將數(shù)值四舍五入為最接近的整數(shù)(這也是我們在數(shù)學(xué)課上學(xué)到的舍入規(guī)則)。

下面是使用這些方法的示例:

alert(Math.ceil(25.9)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.1)); //26
alert(Math.round(25.9)); //26
alert(Math.round(25.5)); //26
alert(Math.round(25.1)); //25
alert(Math.floor(25.9)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.1)); //25

南昌網(wǎng)絡(luò)公司技術(shù)人員總結(jié):對于所有介于25和26(不包括26)之間的數(shù)值,Math.ceil()始終返回26,因?yàn)樗鼒?zhí)行的是向上舍入。Math.round()方法只在數(shù)值大于等于25.5時(shí)返回26;否則返回25。最后,Math.floor()對所有介于25和26(不包括26)之間的數(shù)值都返回25。

以下是一些補(bǔ)充:
ceil():將小數(shù)部分一律向整數(shù)部分進(jìn)位。
如:

Math.ceil(12.2)//返回13
Math.ceil(12.7)//返回13
Math.ceil(12.0)// 返回12

floor():一律舍去,僅保留整數(shù)。
如:

Math.floor(12.2)// 返回12
Math.floor(12.7)//返回12
Math.floor(12.0)//返回12

round():進(jìn)行四舍五入
如:

Math.round(12.2)// 返回12
Math.round(12.7)//返回13
Math.round(12.0)//返回12

相關(guān)文章

最新評論