...

View Full Version : scientific notation of numbers



tspraveena
05-02-2008, 07:28 AM
I have to display numbers using javascript.
Sometimes numbers can be very large like 100000000000000.
So i want to display the numbers in scientific notation.
Is it possible in javascript?
Is there any built in functions to handle this?

Philip M
05-02-2008, 08:31 AM
Javascript can display numbers up to 10 ^ 20, thereafter in scientific/exponential notation.

alert (Math.pow(10,20))
alert (Math.pow(10,21))

You may want to use the method:-
number.toExponential(digits);

The toExponential() method forces a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation. The parameter is an integer specifiying how many digits to the right of the decimal are returned, even if they are zeros.

e.g:-

number = 1234567;
x = number.toExponential(10);
alert (x);




See also:-

http://www.codingforums.com/showthread.php?t=13974

and

http://www.codingforums.com/showthread.php?t=69730



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum