땡굴이가 블로그에 올린 ‘숫자에 1000단위 콤마(,)를 넣어주는 방법 (2)‘를 보고, 저도 작년에 만들었던 함수를 공개해 봅니다. 다른 사람이 만든 함수를 그때그때 복사해서 사용하다가, 코드를 좀 더 짧게 만들어보려고 연구한 성과(?)죠.
Sorry, English translation is not available on this post.
ごめんなさい。このポストには日本語の翻訳を提供しません。
1
2
3
4
5
6
7
8
9
10
11
12
public static function makeCurrency(str:String):String{
	var arr:Array = str.split("");
	var len:uint = arr.length;
 
	for(var i:int=len-1, cnt:int=1; i>0; i--, cnt++){
		if((cnt % 3)==0){
			arr[i] = "," + arr[i];
		}
	}
	str = arr.join("");
	return str;
}

  9 Responses to “숫자에 1000단위 콤마 넣기”

  1. 숫자 콤마찍기 함수…

    숫자에 1000단위 콤마(,) 넣어주는 방법 (2) 숫자에 1000단위 콤마 넣기   갑자기 형님들이 콤마찍기 대회를 열고 계셔서 나도 참가…;;; http://code.google.com/p/ssen-library/source/browse/trunk/src/ssen/core/...

  2. 음수랑 소숫점도 해봐요 ㅋㅋㅋ ^^

  3. changeCurrency…

    우리회사 한상훈 실장님의 블로그를 읽는중 재미있는 글을 읽게 되었다.
    숫자에 천단위 콤마를 넣어주는 코드인데 나도 해보고 싶어서 하게 되었다.
    하고 보니 실장님 소스와 비슷하게 된거 …

  4. 트랙백, 핑백이 잘 되지 않아서 이렇게 글 남겼습니다.
    저도 한번 만들어 봤는데 하다보니 소스가 비슷 ?!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2011 Hangun's World - Blog Suffusion theme by Sayontan Sinha