๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_number_methods.asp
JavaScript Number Methods
The number of milliseconds between 1970-01-02 and 1970-01-01 is 86400000: ... parseInt() parses a string and returns a whole number. Spaces are allowed.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_parseint.asp
JavaScript parseInt() Method
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_number_parseint.asp
JavaScript Number.parseInt()
The Number.parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref_parseint.asp
JavaScript parseInt() Function
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS ... var a = parseInt("10") + "<br>"; var b = parseInt("10.00") + "<br>"; var c = parseInt("10.33") + "<br>"; var d = parseInt("34 45 66") + "<br>"; var e = parseInt(" 60 ") + "<br>"; var f = parseInt("40 years") + "<br>"; var g = parseInt("He was 40") + "<br>"; var h = parseInt("10", 10)+ "<br>"; var i = parseInt("010")+ "<br>"; var j = parseInt("10", 8)+ "<br>"; var k = parseInt("0x10")+ "<br>"; var l = parseInt("10", 16)+ "<br>"; var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l; Try it Yourself ยป
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ js โ€บ js_number_methods_en.html
JavaScript Number Methods. Lessons for beginners. W3Schools in English
The number of milliseconds between 1970-01-02 and 1970-01-01 is 86400000: ... parseInt() parses a string and returns a whole number. Spaces are allowed.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ parseInt
parseInt() - JavaScript - MDN Web Docs
July 8, 2025 - An integer parsed from the given string, or NaN when ยท the radix as a 32-bit integer is smaller than 2 or bigger than 36, or ยท the first non-whitespace character cannot be converted to a number. Note: JavaScript does not have the distinction of "floating point numbers" and "integers" on the language level.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number โ€บ parseInt
Number.parseInt() - JavaScript - MDN Web Docs
July 10, 2025 - The value to parse, coerced to a string. Leading whitespace in this argument is ignored. ... An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the string. If radix is undefined or 0, it is assumed to be 10 except when the number begins with the code unit pairs 0x or 0X, in which case a radix of 16 is assumed.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_number.asp
JavaScript Number() Method
Number() is an ECMAScript1 (JavaScript 1997) feature. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ javascript โ€บ number methods โ€บ .parseint()
JavaScript | Number Methods | .parseInt() | Codecademy
May 31, 2024 - This function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems). ... Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
Find elsewhere
๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ js โ€บ number_parseint.php
JavaScript: Number parseInt() method
This JavaScript tutorial explains how to use the Number method called parseInt() with syntax and examples. In JavaScript, parseInt() is a Number method that is used to parse a string and return its value as an integer number.
๐ŸŒ
Better Programming
betterprogramming.pub โ€บ what-is-the-best-way-to-convert-a-string-to-a-number-in-javascript-67052a1706c6
The Best Way to Convert a String to a Number in JavaScript | by Andrew Koenig-Bautista | Better Programming
March 6, 2020 - Number() is the JavaScript Number constructor called as a function, which performs a type conversion. It attempts to convert any value to a number: false becomes 0, true becomes 1. null becomes 0, undefined becomes NaN.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_number_reference.asp
JavaScript Number Reference
They do not change the original number. For a complete reference to all JavaScript properties and methods, with full descriptions and many examples, go to: W3Schools' Full JavaScript Reference.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number โ€บ parseFloat
Number.parseFloat() - JavaScript - MDN Web Docs
July 10, 2025 - function circumference(r) { if (Number.isNaN(Number.parseFloat(r))) { return 0; } return parseFloat(r) * 2.0 * Math.PI; } console.log(circumference("4.567abcdefgh")); // Expected output: 28.695307297889173 console.log(circumference("abcdefgh")); // Expected output: 0
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Number
Number - JavaScript - MDN Web Docs - Mozilla
Determine whether the passed value is a safe integer (number between -(253 - 1) and 253 - 1). ... This is the same as the global parseFloat() function.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_parsefloat.asp
JavaScript parseFloat() Method
The parseFloat() method parses a value as a string and returns the first number.
๐ŸŒ
DEV Community
dev.to โ€บ sanchithasr โ€บ 7-ways-to-convert-a-string-to-number-in-javascript-4l
7 ways to convert a String to Number in JavaScript - DEV Community
May 15, 2024 - If you need an integer, use parseInt. If you need a floating-point number, use parseFloat. Number() is a good general-purpose option, while the unary plus operator and multiplication by 1 are convenient for quick conversions but might have ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-number-parseint-method
JavaScript Number parseInt() Method - GeeksforGeeks
February 6, 2026 - // Basic string to integer conversion console.log(parseInt("123")); // Stops at non-numeric character console.log(parseInt("45px")); // Using radix parameter (base 2) console.log(parseInt("1010", 2)); // Invalid conversion console.log(parseInt("abc")); ... Value: This parameter contains a string that is converted to an integer. radix: This parameter represents the radix or base to be used and it is optional. ... It returns a number and if the first character can't be converted to a number then the function returns NaN.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_type_conversion.asp
JavaScript Type Conversions
This table shows the result of converting different JavaScript values to Number, String, and Boolean: Values in quotes indicate string values. Red values indicate values (some) programmers might not expect. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
Top answer
1 of 16
3115

The simplest way would be to use the native Number function:

var x = Number("1000")

If that doesn't work for you, then there are the parseInt, unary plus, parseFloat with floor, and Math.round methods.

parseInt()

var x = parseInt("1000", 10); // You want to use radix 10
    // So you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])

Unary plus

If your string is already in the form of an integer:

var x = +"1000";

floor()

If your string is or might be a float and you want an integer:

var x = Math.floor("1000.01"); // floor() automatically converts string to number

Or, if you're going to be using Math.floor several times:

var floor = Math.floor;
var x = floor("1000.01");

parseFloat()

If you're the type who forgets to put the radix in when you call parseInt, you can use parseFloat and round it however you like. Here I use floor.

var floor = Math.floor;
var x = floor(parseFloat("1000.01"));

round()

Interestingly, Math.round (like Math.floor) will do a string to number conversion, so if you want the number rounded (or if you have an integer in the string), this is a great way, maybe my favorite:

var round = Math.round;
var x = round("1000"); // Equivalent to round("1000", 0)
2 of 16
306

Try parseInt function:

var number = parseInt("10");

But there is a problem. If you try to convert "010" using parseInt function, it detects as octal number, and will return number 8. So, you need to specify a radix (from 2 to 36). In this case base 10.

parseInt(string, radix)

Example:

var result = parseInt("010", 10) == 10; // Returns true

var result = parseInt("010") == 10; // Returns false

Note that parseInt ignores bad data after parsing anything valid.
This guid will parse as 51:

var result = parseInt('51e3daf6-b521-446a-9f5b-a1bb4d8bac36', 10) == 51; // Returns true
๐ŸŒ
Medium
medium.com โ€บ @priyanshitaneja โ€บ understanding-javascript-number-and-parseint-a-comprehensive-guide-390020d40d2d
Understanding JavaScript Number() vs parseInt(): A Comprehensive Guide | by Priyanshi Taneja | Medium
July 10, 2024 - This means it can parse a string containing numbers followed by non-numeric characters, returning the parsed number up to that point but returning NaN in case it encounters booleans, null objects, or an undefined data type.