Large Decimal Numbers and Exponential Notation for Google Spreadsheet

Gists

In this report, it has investigated the large decimal numbers and the exponential notation for Google Spreadsheet. When the large decimal numbers are put to the Spreadsheet, the Spreadsheet automatically sets the display value using the exponential notation. In this report, the result when the values are retrieved by Spreadsheet service and Sheets API is shown.

Sample script

At first, please create new Spreadsheet and open the script editor. And please copy and paste the following script. And, please enable Sheets API at Advanced Google services.

function myFunction() {
  const sheetName = "Sheet1";

  // Set values to Spreadsheet.
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName(sheetName);
  const maxDigit = 30;
  const values = Array(maxDigit)
    .fill("")
    .map((_, i) => {
      const v = 1 + Array(i).fill(0).join("");
      return [v, v.length];
    });
  const range = sheet
    .getRange(2, 1, values.length, values[0].length)
    .setValues(values);
  SpreadsheetApp.flush();

  // Retrieve the values using Spreadsheet service and Sheets API.
  const valuesFromSpreadsheetService1 = range.getValues();
  const valuesFromSpreadsheetService2 = range.getDisplayValues();
  const valuesFromSheetsAPI1 = Sheets.Spreadsheets.Values.get(
    ss.getId(),
    `${sheetName}!${range.getA1Notation()}`
  ).values;
  const valuesFromSheetsAPI2 = Sheets.Spreadsheets.Values.get(
    ss.getId(),
    `${sheetName}!${range.getA1Notation()}`,
    { valueRenderOption: "UNFORMATTED_VALUE" }
  ).values;

  // Show the result.
  console.log(valuesFromSpreadsheetService1);
  console.log(valuesFromSpreadsheetService2);
  console.log(valuesFromSheetsAPI1);
  console.log(valuesFromSheetsAPI2);
}

When this script is run, the following values are put to the sheet “Sheet1”.

Large Decimal Numbers and Exponential Notation for Google Spreadsheet

And, the put values are retrieved by Spreadsheet service and Sheets API.

Result

Summary

From the retrieved values, the following results were obtained.

 Share!