UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Convert to integer - Javascript

How to convert a value to integer in javascript

by Athil


Posted on 27 Jun 2018 Category: Javascript Views: 1089


Here I am going to show how to convert variable to integer in javascript.

DEMO

var a = "10";
var b = parseInt(a); 

Here variable a is a string, and b is an integer.  The data type of a variable is defined by the value in it.

So tho do mathematical operations like +,-,*,%,% etc... need to convert integer before doing it.

example

var a = "10";
var b= "20";
c = parseint(a)* parseint(b);
alert(c);

Full Demo Code

<h1> Demo for conveting javascript to integer. </h1>
<input type="button" value="find sum" onclick = "findsum();"/> <br>



<script>
 function findsum()
 {
 
	var a = "10";
	var b= "20";
	c = parseInt(a) * parseInt(b);
	alert(c);

 
 }
</script>

 



Leave a Comment:


Click here to register

Popular articles