MadsterMaddness
MadsterMaddness

Reputation: 735

How to Convert Base 10 to Base 36

I have two columns in my Google Sheets: one column for base 10 and one column for base 36. I have filled out my Base 10 column to go from 1 to 5,000. I would like to create a function in my script that will allow me to take in the value of the Base 10 number and return a value of base 36. (0123456789abcdefghijklmnopqrstuvwxyz) I want to keep the letter lower case so that I won't confuse the number 0 with the letter O.

This is what I have tried so far in my script:

function toBase36(decNumb) {

    var base36 = parseInt(decNumb, 36);

  return parseInt(base36);
}

The code above produces the following result:

enter image description here

How can I edit my code that that I will add the lower case letters?

Upvotes: 0

Views: 2969

Answers (1)

Vytautas
Vytautas

Reputation: 2286

It would be much simpler to use the toString() method.

Instead of var base36 = parseInt(decNumb, 36);

use var base36 = decNumb.toString(36);

Upvotes: 4

Related Questions