CoffeeScript Math - ceil()



Description

The ceil() method accepts a number and returns its ceil value.

Syntax

Given below is the syntax of ceil() method of JavaScript. We can use the same method in the CoffeeScript code.

Math.ceil( x )

Example

The following example demonstrates the usage of the ceil() method in CoffeeScript. Save this code in a file with name 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

Open the command prompt and compile the .coffee file as shown below.

c:\> coffee -c math_ceil.coffee

On compiling, it gives you the following 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);

Now, open the command prompt again, and run the CoffeeScript file as shown below.

c:\> coffee math_ceil.coffee

On executing, the CoffeeScript file produces the following output.

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
Advertisements