Number to Letter

Number to Letter › Number to letter JavaScript

Number to letter JavaScript

Letters
JavaScript code for these numbers

 
Browser consoleruns live
ElementsConsoleSourcesNetwork

The console lines are the generated code running in this page. The strip shows character codes 65–90 (A–Z) and marks each one used.

In JavaScript, convert a number from 1 to 26 to a letter with String.fromCharCode(64 + n): String.fromCharCode(64 + 1) returns "A." Use 96 instead of 64 for lowercase. For spreadsheet columns, where 27 is "AA," loop with (n - 1) % 26.

Type numbers into the tool and pick A1Z26 or column letters. The tool writes the JavaScript for those numbers and runs it in the page, so the console panel shows real output. The code strip marks which character codes from 65 to 90 your numbers use.

How number to letter JavaScript calculator works?

To convert a number to a letter in JavaScript, the number to letter JavaScript calculator adds 64 to the number and reads the character with that code. The calculator splits your list of numbers, checks each one, converts 1–26 with String.fromCharCode(64 + n), or builds column letters (27 = AA) in column mode, and writes runnable JavaScript code for the same numbers. 8 5 12 12 15 becomes HELLO.

  1. Read the numbers

    Spaces, commas, or new lines separate the numbers.

    8 5 12 12 15
  2. Pick the mode

    A1Z26 maps 1–26 to A–Z. Column mode maps any positive number to Excel column letters.

    A1Z26
  3. Run String.fromCharCode(64 + n)

    Each number n becomes the character with code 64 + n (A = 65 in ASCII and Unicode).

    String.fromCharCode(64 + 8) = "H"
  4. Write the code

    The JavaScript snippet and its output appear side by side. Tick lowercase to use code 96 + n.

    HELLO

Column mode runs a while loop: r = (n − 1) % 26, prepend String.fromCharCode(65 + r), then n = Math.floor((n − 1) / 26).

Number to letter JavaScript formula

The number to letter JavaScript formula is a code point offset. letter = character(64 + n) for capitals and character(96 + n) for lowercase, for n from 1 to 26. Column letters use bijective base 26: take (n − 1) mod 26, then divide (n − 1) by 26, and repeat.

Formula

letter = String.fromCharCode(64 + n)
lower = character(96 + n)
col(n): r = (n − 1) mod 26, n = ⌊(n − 1) ÷ 26⌋, repeat

Where

n
number from 1 to 26 (A1Z26) or any positive whole number (columns)
64
ASCII code of @, the character before A (65)
96
ASCII code of `, the character before a (97)
r
remainder 0–25, read as A–Z

Worked example

n = 28, column mode(28 − 1) % 26 = 1 → "B"Math.floor(27 / 26) = 1 → (1 − 1) % 26 = 0 → "A"toColumn(28) = "AB"

Number to letter JavaScript conversion chart

The number to letter JavaScript conversion chart lists all 26 A1Z26 numbers with the ASCII codes and the JavaScript expression. 1 = A (code 65), 13 = M (code 77), and 26 = Z (code 90).

nLetterCode (capital)Code (lowercase)JavaScript expression
1A6597fromCharCode(65) → "A"
2B6698fromCharCode(66) → "B"
3C6799fromCharCode(67) → "C"
4D68100fromCharCode(68) → "D"
5E69101fromCharCode(69) → "E"
6F70102fromCharCode(70) → "F"
7G71103fromCharCode(71) → "G"
8H72104fromCharCode(72) → "H"
9I73105fromCharCode(73) → "I"
10J74106fromCharCode(74) → "J"
11K75107fromCharCode(75) → "K"
12L76108fromCharCode(76) → "L"
13M77109fromCharCode(77) → "M"
14N78110fromCharCode(78) → "N"
15O79111fromCharCode(79) → "O"
16P80112fromCharCode(80) → "P"
17Q81113fromCharCode(81) → "Q"
18R82114fromCharCode(82) → "R"
19S83115fromCharCode(83) → "S"
20T84116fromCharCode(84) → "T"
21U85117fromCharCode(85) → "U"
22V86118fromCharCode(86) → "V"
23W87119fromCharCode(87) → "W"
24X88120fromCharCode(88) → "X"
25Y89121fromCharCode(89) → "Y"
26Z90122fromCharCode(90) → "Z"

Column numbers past 26

nColumn letters
27AA
28AB
52AZ
53BA
78BZ
702ZZ
703AAA
1,000ALL
16,384XFD

JavaScript number to letter examples

// single number
String.fromCharCode(64 + 5);            // "E"

// lookup string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[5 - 1];    // "E"

// whole message
[8, 5, 12, 12, 15].map(n => String.fromCharCode(64 + n)).join(""); // "HELLO"

// letter to number
"E".charCodeAt(0) - 64;                  // 5

String.fromCharCode takes UTF-16 code units; 65 is "A" and 97 is "a." It accepts several codes at once: String.fromCharCode(...[72, 73]) returns "HI."

Column letters in JavaScript

function toColumn(n) {
  let s = "";
  while (n > 0) {
    const r = (n - 1) % 26;
    s = String.fromCharCode(65 + r) + s;
    n = Math.floor((n - 1) / 26);
  }
  return s;
}
toColumn(28);     // "AB"
toColumn(16384);  // "XFD"

const fromColumn = s => [...s.toUpperCase()].reduce((a, c) => a * 26 + c.charCodeAt(0) - 64, 0);
fromColumn("AB"); // 28

Use Math.floor, not bitwise | 0, if the numbers can pass 2,147,483,647.

Frequently asked questions

How do I convert a number to a letter in JavaScript?

Use String.fromCharCode(64 + n). For n = 3 it returns "C."

How do I convert a letter to a number in JavaScript?

Use letter.toUpperCase().charCodeAt(0) - 64. "C" returns 3.

What is the difference between fromCharCode and fromCodePoint?

fromCodePoint handles characters above 65,535, such as emoji. For A to Z both return the same letters.

How do I get lowercase letters?

Use String.fromCharCode(96 + n) or add .toLowerCase().

What is the JavaScript formula for number to letter?

The JavaScript formula is String.fromCharCode(64 + n), so String.fromCharCode(67) returns "C".

What does String.fromCharCode(65) return?

String.fromCharCode(65) returns "A". 90 returns "Z" and 97 returns "a".

How do I map an array of numbers to letters in JavaScript?

Use nums.map(n => String.fromCharCode(64 + n)).join(""). [3, 1, 20] returns "CAT".