javascript math.ceil code example

Example 1: js ceil

Math.ceil(1.2);
// 2

Example 2: Math.ceil

//The Math.ceil() function always rounds a
//number up to the next largest integer.

//Note: Math.ceil(null) returns integer 0
//and does not give a NaN error.

Math.ceil(.95);    // 1
Math.ceil(4);      // 4
Math.ceil(7.004);  // 8
Math.ceil(-0.95);  // -0
Math.ceil(-4);     // -4
Math.ceil(-7.004); // -7

Example 3: math.ceil

Math.ceil(.95);    // 1
Math.ceil(4);      // 4
Math.ceil(7.004);  // 8
Math.ceil(-0.95);  // -0
Math.ceil(-4);     // -4
Math.ceil(-7.004); // -7

Example 4: How does Math.ceil work

Math.ceil(x); //This equals the next whole number after x. X must be a double.

//Example use:
x = Math.ceil(x);
//Now x is equal to x rounded up.

Example 5: javascript math ceiling function

Math.ceil()

Example 6: math.ceiling

//Math.ceil is Javascript, and rounds number up:
let someNum = 0.001;
console.log(Math.ceil(someNum)); //prints 1

/*Note: Math.ceil ceil is lowercase, whereas Math.Ceiling Ceiling 
is uppercase*/

/*Math.Ceiling is C#, and does the same as Math.ceil, but requires 
a decimal or double: */
decimal someDecimal = 2.32m;
Console.WriteLine(Math.Ceiling(someDecimal)); //prints 3
double someDouble = 1.5;
Console.WriteLine(Math.Ceiling(someDouble)); //prints 2
//Sorry for any gramatical issues!

Tags:

Misc Example