
- CoffeeScript 教程
- CoffeeScript - 主頁
- CoffeeScript - 概覽
- CoffeeScript - 環境
- CoffeeScript - 命令列實用工具
- CoffeeScript - 語法
- CoffeeScript - 資料型別
- CoffeeScript - 變數
- CoffeeScript - 運算子和別名
- CoffeeScript - 條件判斷
- CoffeeScript - 迴圈
- CoffeeScript - 理解
- CoffeeScript - 函式
- 面向物件 CoffeeScript
- CoffeeScript - 字串
- CoffeeScript - 陣列
- CoffeeScript - 物件
- CoffeeScript - 範圍
- CoffeeScript - 展開運算子
- CoffeeScript - 日期
- CoffeeScript - 數學
- CoffeeScript - 異常處理
- CoffeeScript - 正則表示式
- CoffeeScript - 類和繼承
- 高階 CoffeeScript
- CoffeeScript - Ajax
- CoffeeScript - jQuery
- CoffeeScript - MongoDB
- CoffeeScript - SQLite
- CoffeeScript 有用資源
- CoffeeScript - 速查手冊
- CoffeeScript - 有用資源
- CoffeeScript - 討論
CoffeeScript 數學 - ceil()
描述
ceil() 方法接受一個數字並返回其向上取整值。
語法
以下是 JavaScript 的 ceil() 方法的語法。 我們可以在 CoffeeScript 程式碼中使用相同的方法。
Math.ceil( x )
示例
以下示例演示瞭如何在 CoffeeScript 中使用 ceil() 方法。 將此程式碼儲存在名為 math_ceil.coffee 的檔案中。
value = Math.ceil 90.15 console.log "The ceil value of 90.15 is : " + value value = Math.ceil 15.90 console.log "The ceil value of 15.90 is : " + value value = Math.ceil -90.15 console.log "The ceil value of -90.15 is : " + value value = Math.ceil -15.90 console.log "The ceil value of -15.90 is : " + value
開啟 命令提示符 並如下所示編譯 .coffee 檔案。
c:\> coffee -c math_ceil.coffee
在編譯時,它會給你以下 JavaScript。
// Generated by CoffeeScript 1.10.0 (function() { var value; value = Math.ceil(90.15); console.log("The ceil value of 90.15 is : " + value); value = Math.ceil(15.90); console.log("The ceil value of 15.90 is : " + value); value = Math.ceil(-90.15); console.log("The ceil value of -90.15 is : " + value); value = Math.ceil(-15.90); console.log("The ceil value of -15.90 is : " + value); }).call(this);
現在,再次開啟 命令提示符,並如下執行 CoffeeScript 檔案。
c:\> coffee math_ceil.coffee
在執行時,CoffeeScript 檔案輸出以下結果。
The ceil value of 90.15 is : 91 The ceil value of 15.90 is : 16 The ceil value of -90.15 is : -90 The ceil value of -15.90 is : -15
coffeescript_math.htm
廣告