javascript - Precise decimal multiplication (js-assessment) -


i working on js-assessment numbers.js exercise. thought should multiply decimal numbers ten power number of digits (e.g. 0.22 -> 0.22*10^2 = 22) precise decimal multiplication in js. solution test.

i checked solution proposed author of test , can't figure out how algorithm working. here code:

function adjust(num) {     var exponent, multiplier;      if (num < 1) {       exponent = math.floor( math.log(num) * -1 );       multiplier = math.pow(10, exponent);        return { adjusted: num * multiplier, multiplier: multiplier };     }      return { adjusted: num, multiplier: 1 };   } 

what proof

math.floor( math.log(num) * -1 )

is enough exponent?


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -