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>
Number the type which is a 64-bit floating point number*.
If you’re looking to convert a string to a number, use
parseFloat. If using
parseInt, I’d recommend always passing the radix too.
- use the Unary
- use the
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
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.