How to get the length of a Number in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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
raja
Published on 03-Feb-2018 17:16:57
Advertisements