---
# System prepended metadata

title: \#168 Excel Sheet Column Title
tags: [leetcode, leetcode-easy]

---

# \#168 Excel Sheet Column Title
## *仿照excel, 把input number轉換成對應的欄位代號(即10進位轉換26進位)*
## Log
 - build 20210410 by syhuang

## xxx
 - xxx
```javascript=
```
## 初見
 - 10進位與26進位轉換
```javascript=
var convertToTitle = function(columnNumber) {
    var a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    a = a.split('');
    var t = columnNumber;
    var chrPow;
    var result = [];
    while(t>0){
        t-=1;//因為A~Z位置為0~25[註1]
        var pos2code = (t)%26;
        result.unshift(a[pos2code]);
        t = parseInt(t/26);
    }
    return result.join('');
};
```
## 備註
 - [註1]: 初見時卡到一個地方, 我把-1這個動作放在loop裡(這樣的話就必須在迴圈中判斷(t%26)=0時商數要-1), 其實這題是偽26進位(因為沒有"0"的情況)
## 參考
 - [-1解釋](https://leetcode.com/problems/excel-sheet-column-title/discuss/441430/Detailed-Explanation-Here's-why-we-need-n-at-first-of-every-loop-(JavaPythonC%2B%2B))
###### tags: `leetcode`, `leetcode-easy`