randRange(100, 9999) NUMBER_SEED.toString().length rand(2) === 0 ? randRange(4, 8) : randRange( -1 * NUMBER_SEED_LENGTH - 4, -1 * NUMBER_SEED_LENGTH ) ZEROES + ( NUMBER_SEED_LENGTH - 1 ) NUMBER_SEED / pow( 10, E - ZEROES ) localeToFixed(BASE, E - ZEROES) floor( BASE ) BASE_STR.substring( 1 ) ZEROES > 0 ? NUMBER_SEED * pow( 10, ZEROES ) : // NOTE: Don't use toFixed unless you have a good reason, // use localeToFixed instead. Here, since we're passing off // to commafy, we need toFixed. (NUMBER_SEED * pow( 10, ZEROES )).toFixed(-1 * ZEROES) commafy( DECIMAL ) BASE_STR + " \\times 10^{" + E + "}" \newcommand{\exponentColor}[1]{\color{purple}{#1}}\newcommand{\leadingColor}[1]{\color{green}{#1}}

Express this number in scientific notation.

PRETTY_DECIMAL

BASE \times 10 E

There are \exponentColor{E} digits to the right of the leading \leadingColor{LEADING} (and to the left of the decimal).

Count the zeroes to the right of the decimal point before the leading \leadingColor{LEADING}: there is 1 zeroare (E + 1) * -1 zeroes.

If you count the leading digit \leadingColor{LEADING} and those zeroes and the 1 zero, there is \exponentColor{E * -1} digit to the right of the decimal point.

If you count the leading digit \leadingColor{LEADING} and those zeroes and the 1 zero, there are \exponentColor{E * -1} digits to the right of the decimal point.

So: PRETTY_DECIMAL = \leadingColor{LEADING}TRAIL \times 10^{\exponentColor{E}}

commafy( pow( 10, E ) )

SCIENTIFIC = {?}

DECIMAL

SCIENTIFIC = BASE_STR \times TEN_POWER

BASE_STR \times TEN_POWER = PRETTY_DECIMAL