There will probably be problems in IE though. If we do:
Code:
var num = 4.6788256E+15;
num *= 1000000;
alert(num);
num = num.toString(7);
document.write(num + ' = ' + parseInt(num, 7));
IE alerts the same as Firefox:
But when IE writes the base 7 number, it's different, and so therefore is the final result. Firefox writes:
33264540354344104223433301 = 4.6788256000000005e+21
IE:
3.3264540354344104226(e+25) = 3
The first part is technically accurate, as is the second given that string value we feed to parseInt. However, mathematically speaking, it's wrong and certainly not even close to the value we're looking for.
I thought, well we can split the string up and do math on it to get the correct answer. I tried that, but I see no way of doing it that comes close. You can take a parseFloat of 3.3264540354344104226 in base 7 and multiply that times Math.pow(7, 25), and that should be it. It is close, but still too far off:
Code:
var num = 4.6788256E+15;
num *= 1000000;
alert(num);
num = num.toString(7);
if(/e/i.test(num)){
document.write(num + ' = ');
num = num.replace(/[()]/g, '').split(/e/i);
num = parseFloat(num[0], 7) * Math.pow(7, eval(num[1]));
document.write(num);
} else {
document.write(num + ' = ' + parseInt(num, 7));
}
Which gives in IE:
3.3264540354344104226(e+25) = 4.4610031216756507e+21
I think I got the math right, so unless I missed something, I'm not sure what else can be done for IE.
Bookmarks