|
Posted by Toby Inkster on 02/01/06 09:39
Cogito wrote:
> I am using a javascript function to generates large numbers. It
> appears that when the number exceeds 20 digits it is displayed in
> scientific notation, that is, a base and an exponent. Is there a way
> to avoid this and display the complete number instead?
Hmm... only seems to so this when outputting in base 10.
<script type="text/javascript">
var num = 12;
var pow = 20;
var answer = 1;
for (var i=1; i<=pow; i++)
{
answer = answer * num;
}
document.write('Binary: ');
document.write(answer.toString(2));
document.write('<br>Base Ten: ');
document.write(answer.toString(10));
</script>
You may need to write your own function to re-implement toString. Loop
through the number doing something like this (pseudo-code follows):
while (number > 1)
{
x = number mod 10;
number = floor(number / 10);
retval = x.toString() + retval.toString();
}
return retval;
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|