multiply and divide values with power of ten in javascript
how can i di开发者_开发问答vide value that has power of 10 in javascript?
For example:
-5x10^-3 * 3x10^-9
is there a way to do this like a
Math.powof(5,-3)
something like that?
Why not use exponent notation?
-5e-3 * 3e-9
which is equivalent to:
-0.005 * 0.000000003;
Note that when dealing with small decimals, javascript arithmatic may not be exact, e.g.
(-5 * Math.pow(10, -3)) * (3 * Math.pow(10,-9)) // -1.5000000000000003e-11
but
-5 * Math.pow(10, -3) * 3 * Math.pow(10,-9) // -1.5e-11
You can try this:
5 × Math.pow(10,-3)
Almost, Math.pow(x, y) where x is is to the power of y so include it in whatever equation you need
Look at Math.pow(base,exponent)
, which lets you take base
to the power of exponent
. From there you can do something like this:
function powOf10(num,exp) {
return num * Math.pow(10,exp);
}
alert(powOf10(5,-3));
here is the examples but what ur main functionality i didn't understand but look this hope you get some
(Math.pow((-5*10),-3)) * (Math.pow(3*10),-9)
or
(-5 * Math.pow(10,-3)) * (3 * Math.pow(10),-9)
精彩评论