google sheet script to convert the Scientific notation in the selected area to number

27 Views Asked by At

Is there any google sheet script to convert the Scientific notation in the selected area to number? I've tried to write a script but not work. Could you please help me? Here's the data of sheet. thank you for your help so much.

function convertScientificToNumber() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var selectedRange = sheet.getActiveRange();
  var values = selectedRange.getValues();

  for (var i = 0; i < values.length; i++) {
    for (var j = 0; j < values[i].length; j++) {
      var cellValue = values[i][j];
      if (!isNaN(cellValue) && typeof cellValue === 'string' && cellValue.toUpperCase().indexOf('E') !== -1) {
        values[i][j] = Number(cellValue);
      }
    }
  }

  selectedRange.setValues(values);
}
1

There are 1 best solutions below

0
Daniel Bailey On

So I looked at your sheet and the data in the cells seem to be a simple number. The numbers showing as scientific notation are doing so just as a view formatting issue. I suggest instead trying to change the formatting of the cells to show only the simple number format. You could also edit the width of the column to ensure it doesn’t default to scientific notation. (Technically I think this is called engineering notation.)