Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Archive > Archives of Old Posts > General Mac Discussion

 
 
Thread Tools Search this Thread Display Modes
Old Aug 13, 2003, 01:38 PM   #1
simX
macrumors 6502a
 
simX's Avatar
 
Join Date: May 2002
Location: Bay Area, CA
Small JavaScript Question

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?
__________________
-- simX
simX is offline   0
Old Aug 13, 2003, 03:54 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
I think this is what you want:
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<SCRIPT>
var longNum=0.987654321987654321;
alert (longNum);
if (longNum.toExponential)
{
alert(longNum.toExponential(5));
}
</SCRIPT>
</BODY>
</HTML>

On Safari (1.1) I only see the first alert.
robbieduncan is offline   0
Old Aug 13, 2003, 04:31 PM   #3
simX
Thread Starter
macrumors 6502a
 
simX's Avatar
 
Join Date: May 2002
Location: Bay Area, CA
Hmm, I thought I tried that and it didn't work... but it actually did. Thanks!
__________________
-- simX
simX is offline   0

 
MacRumors Forums > Archive > Archives of Old Posts > General Mac Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
JavaScript keeps enabling itself nilesisniles iOS 6 1 Nov 27, 2012 04:40 PM
Flash/Javascript Question nightlong Mac Applications and Mac App Store 2 Aug 27, 2012 08:46 PM
Small question about RAM esadb MacBook 10 Jul 18, 2012 06:09 AM
Small question tmshipp Jailbreaks and iOS Hacks 0 Jun 14, 2012 11:34 AM

Forum Jump

All times are GMT -5. The time now is 04:01 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC