Skip to content
// Sheets · Apps Script

getValue vs getDisplayValue in Google Sheets.

Use getValues() for amounts and date logic, and getDisplayValues() for the text shown in a customer report. Compare both with a small invoice example before changing your export.

“I want to know which method to call when reading a cell in Apps Script so my comparisons and conditional logic actually work instead of silently returning the wrong result.”

The script

copy · paste · trigger
readCellValue.gs
Apps Script
// Use fictional data in a test copy; review log privacy before real use.
// A1: Invoice ID; B1: Amount
// A2: 123 formatted as 00000; B2: 12.5 formatted as currency
function inspectInvoiceValues() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const range = sheet.getRange('A2:B2');
  const raw = range.getValues()[0];
  const shown = range.getDisplayValues()[0];

  if (typeof raw[1] !== 'number' || !Number.isFinite(raw[1])) {
    throw new Error('B2 must contain a numeric amount.');
  }

  console.log('Amount for calculation: ' + raw[1]);
  console.log('Amount plus 10: ' + (raw[1] + 10));
  console.log('Invoice text: ' + shown[0] + ' | ' + shown[1]);
}

Need a variant? Gnaw writes a custom version from one sentence — fields, triggers, edge cases handled.

Walkthrough

Choose by the destination

Use typed values for arithmetic, numeric comparisons and date logic. Use displayed strings when preparing a human-readable invoice, email or document that should reflect the cell's current formatting. Reading both arrays from the same range lets one workflow calculate with the underlying amount and render the displayed label.

For a one-off report, copying the displayed cells may be sufficient. Use Apps Script when the same mapping needs to run repeatedly. Neither reading method repairs an invoice ID or amount that was already imported incorrectly.

Check the example's result

In a test sheet, enter 123 in A2 and apply the custom number format 00000. Enter 12.5 in B2 and apply a currency format. The raw amount remains 12.5; adding 10 produces 22.5. The displayed ID is 00123. The displayed currency text follows your sheet's format and locale, so its symbol and separators may differ from another person's sheet. These are fictional test values; review execution-log privacy before logging real invoice information.

Keep an identifier column as plain text when its exact characters matter. A format can display leading zeros, but it cannot recover digits or characters already lost during import.

Dates need a separate decision

A displayed date is text, so do not compare it directly with a Date object. Read the typed value, check that it is a valid Date, and compare timestamps when the job concerns instants. For a calendar-date label, deliberately choose the spreadsheet or business timezone when formatting. A sheet and script with different timezones can produce confusing labels; changing reading methods alone does not define the intended timezone.

Want a custom version?

Describe your sheet and the rule you want. Gnaw writes the Apps Script — fields, triggers, edge cases — in one shot.

FAQ

3 questions
Does getDisplayValues return numbers?
It returns a two-dimensional array of strings. Currency symbols and separators are display text; use getValues for arithmetic.
Can I recover a long identifier with getDisplayValue?
Only the current display can be read. Neither method restores precision or original characters already lost.
Should I parse the displayed currency text back into a number?
Prefer the underlying numeric value when available. Parsing display text introduces locale and formatting decisions that this example avoids.
// one good script a week

Get a working Apps Script snippet in your inbox, weekly.