Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    25
    Thanks
    9
    Thanked 0 Times in 0 Posts

    scientific notation of numbers

    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?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,147
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    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
    Last edited by Philip M; 05-02-2008 at 07:47 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •