All'alba vincerò

At dawn, I will win!

Javascript

숫자 천 단위 콤마(,) 찍기 - toLocaleString()

나디아 Nadia 2024. 3. 12. 15:48

 

 

 

 

숫자 천 단위 콤마(,) 찍기

 

 

toLocaleString()

  • 날짜나 숫자를 문화권에 맞는 표기법의 문자열로 반환
  • number / date / array 에서 활용
number date array
3자리마다 콤마(,) 용자의 문화권에 맞는
시간 표기법으로
년,월, 일, 시간 반환
array 내용을
문자열로 반환
const date = new Data();
date.toLocalString();
// "2024. 03. 12. 오후 15:45:45"

const price = 20000;
price.toLocalString();
// 20,000

const array = [1, 'a', 234, date];
array.toLocalString();
// "1,a,234,2024. 03. 12. 오후 15:45:45"

 

 

 


참고

 

 

[js] 숫자 천 단위로 콤마(,) 찍기 - toLocaleString()

JavaScript 숫자 천 단위로 콤마(,) 찍기 - toLocaleString() 자바스크립트에서 숫자의 천 단위마다 콤마 찍는 방법으로 아래와 같이 toLocaleString()을 활용하는 것이 있다. 변수가 Number 타입일 때만 천 단위

computer-science-student.tistory.com

 

 

[JavaScript] toLocaleString() 활용하기

toLocaleString(); 정의하는 객체 ( = 사용할 곳 ) date / number / array 에서 활용해줍니다! date number array 사용자의 문화권에 맞는 시간표기법으로 년,월,일 시간을 리턴 3자리 숫자마다 콤마 array의 내용을

lily-im.tistory.com