-4

How to pass double values into a JavaScript array:

var a = 15,2;
var tab = [a];

In fact, I'm trying to do not change a's value directly, but I need to deal it implicitly. (in my app the a's value is generated dynamically so I can't explicitly change its comma)

This table should have only one cell, but it's taking two cells.

Any brilliant idea, please?

4
  • JavaScript numeric constants use . as the fraction separator, not ,. Commented Mar 12, 2014 at 14:37
  • That's not a double. The decimal point should be a dot (.): 15.2. Commented Mar 12, 2014 at 14:37
  • 2
    BTW, I don't see how it take two cells : this is a syntax error. Commented Mar 12, 2014 at 14:38
  • It's taking two cells? What are you talking about? var a = 15,2; is a syntax error. Commented Mar 12, 2014 at 14:38

1 Answer 1

3

Number literals use a dot (.) as the decimal point:

var a = 15.2;
//        ^------ dot (.), not comma (,)
var tab = [a];
Sign up to request clarification or add additional context in comments.

8 Comments

In fact, I'm trying to do not change a's value directly, but I need to deal it implicitly.
What do you mean? This doesn't change a's value from anything : your code doesn't even compile.
in my app the a's value is generated dynamically so I can't explicitly change its comma.
Well, you can't have var a = 15,2; in your code, apart in a string.
well than you have a problem @ABCmo.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.