Skip to content

Instantly share code, notes, and snippets.

@jihunleekr
Created November 23, 2015 02:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jihunleekr/d175222e68f296470898 to your computer and use it in GitHub Desktop.
Save jihunleekr/d175222e68f296470898 to your computer and use it in GitHub Desktop.
숫자를 한글발음대로 표기
/**
* 숫자를 한글발음대로 표기
* 구글 스프레드시트에서는 아래의 함수가 없어서 구현함.
* 한글만 지원. (원래 함수는 한자 등의 다양한 타입을 지원함)
*/
function numberstring(num) {
var namesInSeat = ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'],
namesInSeats = ['', '십', '백', '천'],
namesInFourSeat = ['', '만', '억', '조'],
numArr = num.toString().split('').reverse(),
numStr = '',
i
for (i = numArr.length - 1; i >= 0; i--) {
if (numArr[i] > 0) {
numStr += namesInSeat[numArr[i]];
numStr += namesInSeats[i % 4];
}
if (i % 4 == 0) {
numStr += namesInFourSeat[parseInt(i / 4)];
}
}
return numStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment