Sunday, January 11, 2015

JavaScript - Division using Math.Ceil function

Introduction

Here I will explain how to number division in JavaScript or jQuery using Math.ceil() method. Math.ceil() method will rounds number upwards to next nearest integer.

Declaration of Math.ceil() method
Generally we will use Math.ceil() method like as shown below

var result = Math.ceil(45 / 4);
alert(result + ", " + div);

The complete Example using the JavaScritp Math.ceil function.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Whole Number Division in Javascript</title>
<script type="text/javascript">
function Getdivision() {
var result = Math.ceil(45 / 4);
alert("Result: " + result);
}
</script>
</head>
<body>
<form id="form1">
<div>
<input type="button" value="Click to Get Division Value" onclick="Getdivision()" />
</div>
</form>
</body>
</html>


No comments:

Post a Comment