0
var Height=  (rowData.length * 30) + PPPP.top + 10 ;

When i print this i get 9013510... instead of 90 +135+10 = 235. Why does mine turns into concatentaion instead of Addition.

John Cooper
  • 6,915
  • 27
  • 75
  • 99

4 Answers4

3

You probably need to convert PPPP.top to a number, eg.

var Height = (rowData.length * 30) + parseFloat(PPPP.top) + 10;
mqchen
  • 4,185
  • 1
  • 21
  • 20
2

PPPP.top is probably a string. Try:

var Height=  (rowData.length * 30) + parseInt(PPPP.top, 10) + 10 ;
Jakub Konecki
  • 44,908
  • 7
  • 86
  • 126
James Allardice
  • 160,885
  • 21
  • 326
  • 309
  • +1 for specifying the radix when calling [parseInt](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt). – Anders Fjeldstad Jul 07 '11 at 10:29
1

It's probably treating one of the values incorrectly as a string. Try using parseInt and see if that works:

var Height=  (rowData.length * 30) + parseInt(PPPP.top, 10) + 10;
duncan
  • 30,730
  • 12
  • 76
  • 95
  • haha, yes, maybe overkill! In fact as everyone else spotted it's really just the PPPP.top value that requires parseInt – duncan Jul 07 '11 at 11:39
1

You can use parseInt for that.

var Height=  (rowData.length * 30) + parseInt(PPPP.top, 10) + 10 ;

I have changed radix to base 10.

Talha Ahmed Khan
  • 14,542
  • 10
  • 41
  • 48
  • 2
    parseInt should always be given the radix parameter if you want to avoid something like a user's input of 08 being turned into 0 – duncan Jul 07 '11 at 10:30
  • Yes, Thanks. But you know when validation will come into play we have to make sure that everything is ok. Here I just gave the hint how can you handle it. There could be many ways how you want your user input the value. – Talha Ahmed Khan Jul 07 '11 at 10:34