JavaScript provides two methods for converting non-number primitives into numbers: parseInt() and parseFloat() . As you may have guessed, the former converts a value into an integer whereas the latter converts a value into a floating-point number.

Any number literal contained in a string is also converted correctly, so the string "0xA" is properly converted into the number 10. However, the string "22.5" will be converted to 22 , because the decimal point is an invalid character for an integer. Some examples:

var iNum1 = parseInt("1234blue"); //returns 1234

var iNum2 = parseInt("0xA"); //returns 10

var iNum3 = parseInt("22.5"); //returns 22

var iNum4 = parseInt("blue"); //returns NaN

The parseInt() method also has a radix mode, allowing you to convert strings in binary, octal, hexadecimal, or any other base into an integer. The radix is specified as a second argument to parseInt() , so a call to parse a hexadecimal value looks like this:

var iNum1 = parseInt("AF", 16); //returns 175

Of course, this can also be done for binary, octal, and even decimal (which is the default mode):

var iNum1 = parseInt("10", 2); //returns 2

var iNum2 = parseInt("10", 8); //returns 8

var iNum2 = parseInt("10", 10); //returns 10

If decimal numbers contain a leading zero, it’s always best to specify the radix as 10 so that you won’t accidentally end up with an octal value. For example:

var iNum1 = parseInt("010"); //returns 8

var iNum2 = parseInt("010", 8); //returns 8

var iNum3 = parseInt("010", 10); //returns 10

In this code, both lines are parsing the string "010" into a number. The first line thinks that the string is an octal value and parses it the same way as the second line (which specifies the radix as 8). The last line specifies a radix of 10, so iNum3 ends up equal to 10.

Another difference when using parseFloat() is that the string must represent a floating-point number in decimal form, not octal or hexadecimal. This method ignores leading zeros, so the octal number 0908 will be parsed into 908 , and the hexadecimal number 0xA will return NaN because x isn’t a valid character for a floating-point number. There is also no radix mode for parseFloat() .

Some examples of using parseFloat() :

var fNum1 = parseFloat("1234blue"); //returns 1234

var fNum2 = parseFloat("0xA"); //returns 0

var fNum3 = parseFloat("22.5"); //returns 22.5

var fNum4 = parseFloat("22.34.5"); //returns 22.34

var fNum5 = parseFloat("0908"); //returns 908

var fNum6 = parseFloat("blue"); //returns NaN

Read More, Read More

Similar Question Read more here

Answer from Techie on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript | MDN
For example, parseInt("42") and parseFloat("42") would return the same value: a Number 42. The parseFloat function converts its first argument to a string, parses that string as a decimal number literal, then returns a number or NaN.
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
constructor EPSILON isFinite() isInteger() isNaN() isSafeInteger() MAX_SAFE_INTEGER MIN_SAFE_INTEGER MAX_VALUE MIN_VALUE NaN NEGATIVE_INFINITY POSITIVE_INFINITY parseFloat() parseInt() prototype toExponential() toFixed() toLocaleString() toPrecision() toString() valueOf() JS Objects
Top answer
1 of 2
57

JavaScript provides two methods for converting non-number primitives into numbers: parseInt() and parseFloat() . As you may have guessed, the former converts a value into an integer whereas the latter converts a value into a floating-point number.

Any number literal contained in a string is also converted correctly, so the string "0xA" is properly converted into the number 10. However, the string "22.5" will be converted to 22 , because the decimal point is an invalid character for an integer. Some examples:

var iNum1 = parseInt("1234blue"); //returns 1234

var iNum2 = parseInt("0xA"); //returns 10

var iNum3 = parseInt("22.5"); //returns 22

var iNum4 = parseInt("blue"); //returns NaN

The parseInt() method also has a radix mode, allowing you to convert strings in binary, octal, hexadecimal, or any other base into an integer. The radix is specified as a second argument to parseInt() , so a call to parse a hexadecimal value looks like this:

var iNum1 = parseInt("AF", 16); //returns 175

Of course, this can also be done for binary, octal, and even decimal (which is the default mode):

var iNum1 = parseInt("10", 2); //returns 2

var iNum2 = parseInt("10", 8); //returns 8

var iNum2 = parseInt("10", 10); //returns 10

If decimal numbers contain a leading zero, it’s always best to specify the radix as 10 so that you won’t accidentally end up with an octal value. For example:

var iNum1 = parseInt("010"); //returns 8

var iNum2 = parseInt("010", 8); //returns 8

var iNum3 = parseInt("010", 10); //returns 10

In this code, both lines are parsing the string "010" into a number. The first line thinks that the string is an octal value and parses it the same way as the second line (which specifies the radix as 8). The last line specifies a radix of 10, so iNum3 ends up equal to 10.

Another difference when using parseFloat() is that the string must represent a floating-point number in decimal form, not octal or hexadecimal. This method ignores leading zeros, so the octal number 0908 will be parsed into 908 , and the hexadecimal number 0xA will return NaN because x isn’t a valid character for a floating-point number. There is also no radix mode for parseFloat() .

Some examples of using parseFloat() :

var fNum1 = parseFloat("1234blue"); //returns 1234

var fNum2 = parseFloat("0xA"); //returns 0

var fNum3 = parseFloat("22.5"); //returns 22.5

var fNum4 = parseFloat("22.34.5"); //returns 22.34

var fNum5 = parseFloat("0908"); //returns 908

var fNum6 = parseFloat("blue"); //returns NaN

Read More, Read More

Similar Question Read more here

2 of 2
12

First of all only parseInt accepts second argument. It's called radix. It represents numeral system to be used. In example you can convert number into binary or hexadecimal code.

parseFloat only accepts one argument.

🌐
Medium
medium.com › @roy.elaawar › parsefloat-vs-parstint-in-javascript-4f3d345f205f
ParseFloat vs ParseInt in JavaScript | by Roy Elaawar | Medium
November 6, 2023 - In summary, use parseInt when you want to convert a string to an integer, and use parseFloat when you want to convert a string to a floating-point number.
🌐
Bennadel
bennadel.com › blog › 2012-exploring-javascripts-parseint-and-parsefloat-functions.htm
Exploring Javascript's parseInt() And parseFloat() Functions
April 21, 2020 - Other than not treating "0x" as base16 or "012" as base8, the only significant difference is that parseFloat() returns decimals for values like "123.456" where as parseInt() would just return 123.
🌐
Quora
quora.com › What-is-the-difference-between-parseInt-and-parseFloat-in-JavaScript
What is the difference between parseInt() and parseFloat() in JavaScript? - Quora
Answer (1 of 4): In short answer, with [code ]parseInt()[/code] you can parses a string into Integer Number, and with [code ]parseFloat()[/code] you can parses a string into Floating Number.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript | MDN
For example, parseInt("2", 2) returns NaN because 2 is not a valid numeral in the binary number system. Likewise, although 1e3 technically encodes an integer (and will be correctly parsed to the integer 1000 by parseFloat()), parseInt("1e3", 10) returns 1, because e is not a valid numeral in base 10.
🌐
Copahost
copahost.com › home › javascript parsefloat: examples and variations of this function
Javascript parseFloat: Examples and variations of this function - Copahost
July 16, 2023 - Use parseFloat() when you need to extract a floating-point number that may contain decimal places. It will preserve the fractional part and return a floating-point number. Numeric Base: If you are parsing strings representing numbers in different bases, such as binary, octal, or hexadecimal, you should use parseInt() with the appropriate radix (base) parameter.
🌐
Zapier
community.zapier.com › featured-articles-65 › javascript-code-parsefloat-vs-parseint-16320
JavaScript Code: parseFloat VS parseInt | Zapier Community
June 17, 2022 - parseInt() returns the first integer (w/ decimals) parseFloat() returns the first number (w/o decimals) NOTE: Input Data are all treated as strings.
🌐
W3Schools
w3schools.com › jsref › jsref_number_parsefloat.asp
JavaScript Number.parseFloat()
The Number.parseFloat() method parses a value as a string and returns the first number.
🌐
GitHub
github.com › microsoft › TypeScript › issues › 50828
ParseInt and ParseFloat should accept numbers and BigInt as Input · Issue #50828 · microsoft/TypeScript
August 2, 2022 - parseInt(854n); // Should work with bigInt parseInt(548.25); // Should work too with numbers parseFloat(854n); // Should work with bigInt parseFloat(548.25); // Should work too with numbers // Using wrappers const n = new Number(55); parseInt(n); // Should work
Published   Sep 18, 2022
🌐
Bennadel
bennadel.com › blog › 3803-i-prefer-the-unary-plus-operator-over-parseint-and-parsefloat-when-coercing-strings-to-numbers-in-javascript.htm
I Prefer The Unary Plus (+) Operator Over parseInt() And ParseFloat() When Coercing Strings To Numbers In JavaScript
April 4, 2020 - Both the parseInt() and the parseFloat() methods parse the input string until they hit a non-numeric value, at which point they discard the rest of the input. So, to be clear, this is parseInt() working exactly how it was designed to work.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-number-parsefloat-method
JavaScript Number parseFloat() Method - GeeksforGeeks
July 11, 2025 - let x = parseFloat("3.14"); if (isNaN(x)) console.log("x is not a number"); else console.log("x is a number"); let y = parseFloat("geeksforgeeks"); if (isNaN(y)) console.log("y is not a number"); else console.log("y is a number"); // Difference between parseInt() and parseFloat() let v1 = parseInt("3.14"); let v2 = parseFloat("3.14"); console.log('Using parseInt("3.14") = ' + v1); console.log('Using parseFloat("3.14") = ' + v2); Output: x is a number y is not a number Using parseInt("3.14") = 3 Using parseFloat("3.14") = 3.14 ·
🌐
Java-samples
java-samples.com › showtutorial.php
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
JavaScript provides two methods for converting non-number primitives into numbers: parseInt() and parseFloat() . As you may have guessed, the former converts a value into an integer whereas the latter converts a value into a floating-point number. These methods only work properly when called ...
🌐
Cullen Web Services
cullenwebservices.com › home › javascript numbers: number(), parseint(), parsefloat()
JavaScript Numbers: Number(), parseInt(), parseFloat() - Cullen Web Services
December 11, 2015 - parseInt("10",16); //hexadecimal 16 parseInt("10",8); //octal 8 parseInt("10",10); //decimal 10 · parseFloat(true); //NaN parseFloat(false); //NaN parseFloat(13); //13 parseFloat("13"); //13 var j; //undefined parseFloat(j); //NaN var b=10; parseFloat(b) //10 parseFloat("1.5") //1.5 parseFloat("01.5") //1.5 parseFloat("0xA") //0 only uses decimal system parseFloat("") //NaN parseFloat("cindy"); //NaN parseFloat("123cindy") //123.123 parseFloat("4.89e7"); //48900000
🌐
Alibaba Cloud
topic.alibabacloud.com › a › the-difference-between-number--parseint--and-parsefloat--in-js_1_11_30521894.html
The difference between number (), parseint (), and parsefloat () in JS
In other words, the first decimal point in the string is valid, and the second decimal point is invalid, and the string after it will be ignored. parseFloat() only parses decimal, so it does not have the second parameter to specify the usage of the radix If the string contains a number that can be parsed as a positive number (no decimal point, or zero after the decimal point), parseFloat() will return an integer. example: var num1 = parseFloat("123AF"); //123 Var num2 = parseFloat("0xA"); //0 Var num3 = parseFloat("22.5"); //22.5 Var num4 = parseFloat("22.3.56"); //22.3 Var num5 = parseFloat("0908.5"); //908.5 The difference between parseInt() and parseFloat() is: The first decimal point in the string parsed by parseFloat() is valid, while parseInt() will stop parsing when it encounters a decimal point, because the decimal point is not a valid number character.
Top answer
1 of 3
2
They do different things. Sure, they both convert "100", but parseFloat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) will also convert something like "33.3". On the other hand, parseInt (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) will enforce acceptance of only integer input, and it will also take a second argument that allows you to specify a conversion radix other than decimal. What does the hex value "F00D" represent? parseInt("F00D", 16) will tell ya!
2 of 3
1
Hey there! I have found some discussions that cover the difference between using the two. https://stackoverflow.com/a/12813049/7932859 https://stackoverflow.com/a/9528452/7932859 Here are also the docs for the different usages. + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/GlobalObjects/parseInt + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/GlobalObjects/parseFloat parseInt() has an extra parameter called "radix" which is describes as radix: An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify 10 for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10. I hope this helps!
🌐
SitePoint
sitepoint.com › javascript
The advantage of using Number() instead of parseInt or parseFloat
May 30, 2023 - What is the advantage of using Number() instead of parseInt or parseFloat?