JS Tutorial



JS NUMBER METHODS


JavaScript Number Methods

In JavaScript, the Number object provides a variety of methods for working with numeric values. These methods allow you to perform operations like converting a string to a number, checking for integer values, and rounding numbers, among others.

🔹 Key JavaScript Number Methods:
  • toFixed() – Formats a number to a fixed number of decimal places
  • parseInt() – Converts a string to an integer
  • parseFloat() – Converts a string to a floating point number
  • isNaN() – Determines whether a value is NaN (Not a Number)
  • isFinite() – Checks if a number is finite

📌 toFixed()

The toFixed() method formats a number to a fixed number of decimal places.

Example: Rounding a Number

📌 parseInt() and parseFloat()

parseInt() converts a string to an integer, while parseFloat() converts a string to a floating-point number.

Example: Parsing a String to Number

📌 isNaN()

The isNaN() function checks if a value is NaN (Not a Number).

Example: Check if Value is NaN

📌 isFinite()

The isFinite() method checks whether a number is finite. It returns true if the value is a finite number, and false otherwise.

Example: Check if Number is Finite

📌 Try It Yourself

Select a number operation and see it in action below:



Operation result will appear here
📘 Summary:
JavaScript Number methods allow you to perform various number operations, such as rounding decimals, converting strings to numbers, and checking for NaN or finite numbers. These methods help manage numbers effectively in your code.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review