You are here: Re: Display of large numbers « HTML « IT news, forums, messages
Re: Display of large numbers

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация