Reputation: 31
Is it possible to change # of decimal places of all cells in Google Sheets with app script? I'm trying to create a dropdown button in Google Sheets where the user can select the # of decimal places to display in current worksheet. I've checked the app script documentation but didn't find anything regarding this.
Upvotes: 2
Views: 16303
Reputation: 11
You can use the setNumberFormat()
function within the Range object.
https://developers.google.com/apps-script/reference/spreadsheet/range#setnumberformatnumberformat
SpreadsheetApp.getActiveSheet().getRange("A1").setNumberFormat("0.00")
Upvotes: 1
Reputation: 476
I am not aware of a Google Sheets formula to allow for this. There are also not GAS specific methods to perform the function as far as I have seen. There are, however, some universal JavaScript methods to mimic this.
You can find the documentation for the .toFixed()
method here. This method changes a number to a string with the specified decimal places. This will change the output format so be aware of the type of data you are working with.
Upvotes: 1