3

So I want to give JS a number in exponential notation. Amazingly, I haven't found a reference on how to do this.

Why doesn't this work?

 var tempdec = 8.85956e-8;

I don't have to do

 var tempdec = parseFloat('8.95956e-8');

...do I?

... answered below.

The upshot: It does work.

However, using var in the console returns undefined. But it works nonetheless.

6
  • Remember to end the line in a semicolon. Commented Jan 26, 2015 at 1:05
  • It works fine for me. Define "doesn't work". Commented Jan 26, 2015 at 1:05
  • Returns 'undefined' in at least the Chrome Dev Tools console. Commented Jan 26, 2015 at 1:07
  • 1
    see also stackoverflow.com/questions/14633968/… Commented Jan 26, 2015 at 1:34
  • 1
    this one even better stackoverflow.com/questions/22844840/… Commented Jan 26, 2015 at 1:36

1 Answer 1

1

Numbers in javascript are floating point integers, so you don't have to use parseFloat('8.95956e-8') as 8.85956e-8 is same.

Try this in the console:

var tempdec = 8.85956e-8;
console.log(tempdec);//It logs 8.85956e-8 not undefined
console.log(parseFloat(tempdec));//Logs the same as above...
Sign up to request clarification or add additional context in comments.

4 Comments

Okay... do you have any insight as to my initial question? Specifically, why var tempdec = 8.85956e-8; returns undefined?
@JoshuaPenman Because your line of code doesn't return anything for the console to output. If you enter tempdec it will show the value.
I thought I knew a little about floating point, but I don't know what "floating point integers" are. Could someone give me a hint?
nothing. I wanted to mean numbers...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.