# Number.parseFloat()

## Why parseFloat ?

The Number.parseFloat () method is used to accept the javascripte array and convert it to a floating-point number. This function determines whether the first character in the specified string is a number. So, it parses the string to the end of the number and returns the number as a string in numbers.
The Number.parseFloat () method returns the NaN value if the first number in the array is not converted. (Only the first number in the string is returned)

Syntax:

parseFloat(value)

• value (required): The value to be parsed.

### JavaScript parseFloat Examples

Example 1

``````        let val1 = Number.parseFloat(1234);
let val2 = Number.parseFloat(1.55);
let val3 = Number.parseFloat(-8.99);
let val4 = Number.parseFloat(0);
let val5 = Number.parseFloat(null);
let val6 = Number.parseFloat("394");
let val7 = Number.parseFloat("truecodes.org");
let val8 = Number.parseFloat(2000 / 1000);
let val9 = Number.parseFloat(Infinity);
let val10 = Number.parseFloat(-Infinity);
let val11 = Number.parseFloat(0 / 0);
let val12 = Number.parseFloat(function () { });
let val13 = Number.parseFloat(2019 / 02 / 03);

console.log(val1);
console.log(val2);
console.log(val3);
console.log(val4);
console.log(val5);
console.log(val6);
console.log(val7);
console.log(val8);
console.log(val9);
console.log(val10);
console.log(val11);
console.log(val12);
console.log(val13);``````

output:

1234
1.55
-8.99
0
NaN
394
NaN
36 2
Infinity
-Infinity
NaN
NaN
336.5

Example 2

The Number.parseFloat () method returns the first number in the entered value to you. For example, in an article he will return the first type of number he sees.

``````        let parseFloat1 = Number.parseFloat(
"JavaScript is a scripting or programming language that allows you to implement complex things on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which (HTML and CSS) we have covered in much more detail in other parts of the Learning Area.")

let parseFloat2 = Number.parseFloat(
" 1 : JavaScript is a scripting or programming language that allows you to implement complex things on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which (HTML and CSS) we have covered in much more detail in other parts of the Learning Area.")

console.log(parseFloat1)
console.log(parseFloat2)``````

output:

NaN
1

### Browser Support

 Chrome yes Edge yes Firefox 25 Internet Explorer no Opera 9 Safari yes Android webview yes Chrome for Android yes Edge mobile yes Firefox for Android 25 Opera Android yes

### 1 Comment »

This site uses Akismet to reduce spam. Learn how your comment data is processed.