javascript - How to recognize that integer value is thousands, hundreds, or tens? -



javascript - How to recognize that integer value is thousands, hundreds, or tens? -

i have several numbers proceed, let's assume numbers : 14000,32100,510,2100, , 10000 so, how create numbers recognized thousands or hundreds in javascript? there function this?

use logarithm. base of operations 10 log if available, or create base of operations 10 log natural log (ln) via ln(n)/ln(10). so:

var log10=function(n){return math.log(n)/math.log(10);}; log10(100); //2 log10(10000); //4 log10(1000000);//6, uh 5.999999999999999

might need round result due lack of precision. rounded version:

function log10(n){ homecoming math.round(100*math.log(n)/math.log(10))/100; } [10,100,1000,10000,100000,1000000].map(log10); /* 1,2,3,4,5,6 */

also should cache math.log(10) result if performance issue;

javascript function integer

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -