How to get the length of a Number in JavaScript?


Use the toString() method to covert the Number to string, then the length() method gives you length.

Example

You can try to run the following code to learn how to get the length of a Number −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var num1 = 344;
         var num2 = 149856;

         document.write("Length of number "+num1+" = "+ num1.toString().length);
         document.write("<br>Length of number "+num2+" = "+ num2.toString().length);
      </script>
   </body>
</html>

Output

Length of number 344 = 3
Length of number 149856 = 6

Updated on: 17-Jun-2020

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements