LearnFast.Ninja

JavaScript cast to int

This tutorial will show you how to convert float to integer or string to integer.

Main idea:
parseInt(8.432); // 8
parseInt('9'); // 9

Working example code:

<!DOCTYPE html>

<html>

<head>

    <title>Untitled Page</title>

    <script type="text/javascript">

        var Example_1 = parseInt(8.432); // 8

        var Example_2 = parseInt('9'); // 9

        document.writeln(Example_1);

        document.writeln(Example_2);

    </script>

</head>

<body>

</body>

</html>


Result:


Tags

javascript

int cast parse parseint integer