Trunc() and Round() math methods in Javascript
Trunc() and Round() math methods in Javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test Page</title>
</head>
<body>
<script type="text/javascript">
var a = 1.5;
var b = 1.49;
var c = -1.22;
var d = -1.50;
var x = Math.round(a);
var y = Math.round(b);
var z = Math.round(c);
var q = Math.round(d);
var xx = Math.trunc(a);
var yy = Math.trunc(b);
var zz = Math.trunc(c);
var qq = Math.trunc(d);
console.log(x);
console.log(y);
console.log(z);
console.log(q);
console.log(xx);
console.log(yy);
console.log(zz);
console.log(qq);
</script>
</body>
</html>
Comments
Post a Comment
I WOULD APPRECIATE IF YOU LEAVE A COMMENT OR YOUR FEEDBACK HERE !!!