- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 −
<!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
Advertisements