These number methods can be used on all JavaScript numbers:
Method | Description |
---|---|
toString() | Returns a number as a string |
toExponential() | Returns a number written in exponential notation |
toFixed() | Returns a number written with a number of decimals |
toPrecision() | Returns a number written with a specified length |
ValueOf() | Returns a number as a number |
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = "99";
var num = Number(a);
document.write(num + 10 +"<br>");
var b = true;
var num = Number(b);
document.write(num +"<br>");
/* ParesInt Method */
var c = "10.00";
var num = parseInt(c);
document.write(num + "<br>");
/* ParesFloat Method */
var m = "10.33";
var num = parseFloat(m);
document.write(num + "<br>");
/* IsFinite Method */
var n = 100;
var num = Number.isFinite(n);
document.write(num + "<br>");
/* IsInteger Method */
var x = 10.50;
var num = Number.isInteger(x);
document.write(num + "<br>");
/* ToFixed Method */
var y = 5.56789;
var num = y.toFixed(2);
document.write(num + "<br>");
/* ToPrecision Method */
var z = 5.56789;
var num = z.toPrecision(3);
document.write(num + "<br>");
</script>
</head>
<body>
</body>
</html>