0
votes

I have a script that processes a google spreadsheet. if I have a variable "myVariable" which has a value of 2.10 and use the function SpreadsheetApp.getActiveSheet().getRange(,).setValue(myVariable) it is stored as 2.1 instead of 2.10. When I call the value again, the last decimal places get truncated if they are zero. Since these are fiscal numbers I need to keep the two decimal places.

Is there a way to prevent this?

1

1 Answers

0
votes

You can just format the cell in the sheet from Format>Number>Automatic to Format>Number>Number.

But if you want to achieve it using App script itself then just add this line :

var myVariable = 2.10;
SpreadsheetApp.getActiveSheet().getRange(,).setValue(myVariable);
SpreadsheetApp.getActiveSheet().getRange(,).setNumberFormat("0.00"); // Add this line to your code