var x = 123456789; x.toString().length;
Complete HTML example code:
Note: This process will also work for Float Numbers and for Exponential numbers also.
<!DOCTYPE HTML> <html> <body> <script> var x = 123456789; var res = x.toString().length; alert(res); </script> </body> </html>
If you don’t want to use the toString() method then add an empty string. It will implicitly cause a number to turn into a string.
var mynumber = 123; alert((""+mynumber).length);
One more Math (best performance in Chrome, Firefox but slowest in ie11)
var num = 123 alert(Math.floor( Math.log(num) / Math.LN10 ) + 1)
Do comment if you have any doubts and suggestions on this JS number topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.