Math的用法!! 學的較淺

2021-07-09 04:02:31 字數 900 閱讀 5117

小數值捨入為整數的幾個方法:

1.math.ceil()執行向上捨入,即它總是將數值向上捨入為最接近的整數;

2.math.floor()執行向下捨入,即它總是將數值向下捨入為最接近的整數;

3.math.round()執行標準捨入,即它總是將數值四捨五入為最接近的整數; 1

2

3

4

5

6

7

8

9

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

Math物件的用法

math物件在js中常常處理一些數學數值的問題 math物件並不像date和string那樣是物件的類,因此沒有建構函式math 像math.abs 這樣的函式只是函式,不是某個物件的方法。因此,我們不需要建立它,可以直接把它作為物件直接使用就可以呼叫它的所有屬性和方法。對於負數取正處理,取絕對值 ...

js的Math的簡單用法

math是乙個數學集合,裡面有關於很多函式的應用,我們羅列一些簡單的應用 var num 12.34 有這麼乙個數字 var floornum math.floor num 結果為12,這是向下取整 如果這個數時 12.34呢?那麼結果為 13 var ceilnum math.ceil num 結...

C 的auto用法學習

學習內容參考 auto 可以在宣告變數的時候根據變數初始值的型別自動為此變數選擇匹配的型別,類似的關鍵字還有decltype。auto關鍵字必須在定義的時候賦予初始化值 類似於const 在沒有auto的時候,我們操作標準庫時經常需要這樣 include includeint main 使用auto...