JavaScript do not provide parseLong() function. You can use the parseFloat() method, Int in javascript is a float since JavaScript has only one number type.
JavaScript parseLong
Simple example code.
<!DOCTYPE html>
<html>
<body>
<script>
var myInt = parseInt("10.256");
console.log(myInt)
console.log(typeof(myInt))
var myFloat = parseFloat("10.256");
console.log(myFloat)
console.log(typeof(myFloat))
</script>
</body>
</html>
Output:
JavaScript has a Number
the type which is a 64-bit floating point number*.
If you’re looking to convert a string to a number, use
- either
parseInt
orparseFloat
. If usingparseInt
, I’d recommend always passing the radix too. - use the Unary
+
operator e.g.+"123456"
- use the
Number
constructor e.g.var n = Number("12343")
*there are situations where the number will internally be held as an integer
Do comment if you have any doubts or suggestions on this Js code.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version