tony873004

09-13-2008, 05:06 AM

Math.log(1000) / Math.log(10) = 3, not 2.9999999999996

How do I make Javascript acknowledge this, even if I must lose the final digit?

I've tried this:

g = Math.log(a)/Math.log(b);

g = g * 10000000000000;

g = g + +0.0000000000005;

g = parseInt(g);

g = parseFloat(g / 10000000000000);

which is typical code for rounding. But it didn't work. I lost the final 6, but I still get a string of 9s.

Thanks!

How do I make Javascript acknowledge this, even if I must lose the final digit?

I've tried this:

g = Math.log(a)/Math.log(b);

g = g * 10000000000000;

g = g + +0.0000000000005;

g = parseInt(g);

g = parseFloat(g / 10000000000000);

which is typical code for rounding. But it didn't work. I lost the final 6, but I still get a string of 9s.

Thanks!