convert string to number javscript code example

Example 1: convert string to number javascript

var myString = "869.99"
var myFloat = parseFloat(myString)
var myInt = parseInt(myString)

Example 2: javascript string to a decimal

<script language="JavaScript" type="text/javascript">
var a = "3.3445";
var c = parseFloat(a);
alert(c);
</script>

Example 3: javascript type casting int

Number("3.14") // returns 3.14
false.toString()   // returns "false"
String(false)      // returns "false"

Example 4: string to number javascript

new Number(valeur);
var a = new Number('123'); // a === 123 donnera false
var b = Number('123'); // b === 123 donnera true
a instanceof Number; // donnera true
b instanceof Number; // donnera false