Nearby lessons

38 of 40

🔢 JavaScript String to Number Conversion & Number Methods

📌 What are JavaScript Number Methods?

This section demonstrates how to convert strings and other values to numbers in JavaScript using built-in methods.

It also showcases how to work with numeric precision, validation, and formatting using various Number methods.

🔸 Convert String to Number using Number()

Number() is used to convert string or boolean values into numbers.

Example02
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Convert Boolean to Number

Using Number(true) returns 1 and Number(false) returns 0.

Example03
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 parseInt() Method

parseInt() converts a string to an integer by removing decimal values.

Example04
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 parseFloat() Method

parseFloat() converts a string to a floating-point number.

Example05
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Number.isFinite() Method

Number.isFinite() checks whether the value is a finite number (not Infinity or NaN).

Example06
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Number.isInteger() Method

Number.isInteger() checks if a value is an integer.

Example07
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 toFixed() Method

toFixed() formats a number using fixed-point notation (number of decimals).

Example08
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 toPrecision() Method

toPrecision() formats a number to a specified length (significant digits).

Example09
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

10 Questions
Progress: 0 / 10