-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?

ABCmo
  • 239
  • 1
  • 6
  • 16

1 Answers1

3

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

var a = 15.2;
//        ^------ dot (.), not comma (,)
var tab = [a];
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • In fact, I'm trying to do not change `a`'s value directly, but I need to deal it implicitly. – ABCmo Mar 12 '14 at 14:38
  • 1
    What do you mean? This doesn't change a's value from anything : your code doesn't even compile. – Denys Séguret Mar 12 '14 at 14:39
  • in my app the `a`'s value is generated dynamically so I can't explicitly change its comma. – ABCmo Mar 12 '14 at 14:40
  • Well, you can't have `var a = 15,2;` in your code, apart in a string. – Denys Séguret Mar 12 '14 at 14:41
  • well than you have a problem @ABCmo. – epascarello Mar 12 '14 at 14:41
  • @ABCmo Generated how? Surely not as a number, because that would have the `.` instead of `,`. If it is generated as a String `"15,2"` you can just replace the comma by a dot and `parseFloat`. – Daniël Knippers Mar 12 '14 at 14:43
  • @DaniëlKnippers, I'm building an ASP.NET MVC web-app, so, I'm sending from Controllor a double value with `15,2` to finally display it into the View. [You can find more details about my code, here.](http://stackoverflow.com/questions/22273992/how-to-make-a-foreach-loop-into-javascript) – ABCmo Mar 12 '14 at 14:46
  • That other question and answer are based on a terrible practice. Don't generate JS code from ASP ! You should generate data in a standard exchange format (JSON comes to mind) and then (client side) insert those data where necessary. – Denys Séguret Mar 12 '14 at 14:53