Home > Back-end >  How do you add 0.1 to a setvalue?
How do you add 0.1 to a setvalue?

Time:02-18

I have a variable ekeys, which basically creates a ruler down a page and sets a depth (elevation) value down the ruler compared to the 0 value.

i.e. the ruler will show 1 metre depth. If surface elevation is set to 4.2 metres, then 1 metre down the corresponding elevation will be 4.2 metres minus 1 metre - which = 3.2 metres. For some reason it is 0.1 m out (i.e. showing 3.1 metres instead of 3.2 metres).

Is there an easy way to change this code: setValue(eKeys[k])

to add 0.1?

i.e. .setValue(eKeys[k] 0.1) <--- this does not work (it shows a value of 30.2 instead of 3.2).

var rKeys = Object.keys(mergeThisRows);
  var eKeys = Object.keys(mergeThisRowsE);
  for (k = 0; k < rKeys.length; k  ) {
    shTemplate.getRange(mergeThisRows[rKeys[k]]   STARTT_ROW - 1, DEPTH_COL   1, 2, 1).breakApart().merge().setValue(rKeys[k]).setFontColor("black").setFontSize(6).setVerticalAlignment("top").setHorizontalAlignment("right");
    shTemplate.getRange(mergeThisRows[rKeys[k]]   STARTT_ROW - 1, DEPTH_COL   1, 2, 1).setBorder(true, null, null, null, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);;
    if (eKeys[k] != undefined) {
      shTemplate.getRange(mergeThisRowsE[eKeys[k]]   STARTT_ROW - 1, ELEVATION_COL   1, 2, 1).breakApart().merge().setValue(eKeys[k]).setNumberFormat("0.0").setFontColor("black").setFontSize(6).setVerticalAlignment("top").setHorizontalAlignment("right");
      shTemplate.getRange(mergeThisRowsE[eKeys[k]]   STARTT_ROW - 1, ELEVATION_COL   1, 2, 1).setBorder(true, null, null, null, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);
    }
  }

CodePudding user response:

setValue(parseInt(eKeys[k]) 0.2)
-> 3.2

CodePudding user response:

I'd propose to use the unary operator to convert the string into a number:

setValue( eKeys[k])   0.2)

Reference

  • Related