Small JavaScript Question

Discussion in 'General Mac Discussion' started by simX, Aug 13, 2003.

  1. simX
    Expand Collapse
    macrumors 6502a


    May 28, 2002
    Bay Area, CA
    I've been doing some tiny JavaScript stuff for web pages, and I've run across a problem. I want to convert some large numbers into exponential notation.

    It seems the method is varname.toExponential(a), where a inside is the number of decimal places to which you want the number rounded.

    The problem is, this method seems to not work with Safari, so I was wondering what the best way is to check if a browser supports this method, and if it doesn't, then just display the big long number. I don't want to simply browser sniff for Safari, because other browsers (like Mac IE) don't support it either -- so it would be nice just to check if the browser supports the function, and then use it if it does.

    Any suggestions?
  2. robbieduncan
    Expand Collapse
    Moderator emeritus


    Jul 24, 2002
    I think this is what you want:
    var longNum=0.987654321987654321;
    alert (longNum);
    if (longNum.toExponential)

    On Safari (1.1) I only see the first alert.
  3. simX
    Expand Collapse
    thread starter macrumors 6502a


    May 28, 2002
    Bay Area, CA
    Hmm, I thought I tried that and it didn't work... but it actually did. Thanks! :)

Share This Page