728x90
원인이나 세세한 설명보다는 바로 쓸 수 있는 기술을 지향합니다.
1.toLocaleString()
숫자. toLocaleString()
Number.prototype.toLocaleString() - JavaScript | MDN
The toLocaleString() method returns a string with a language-sensitive representation of this number. In implementations with Intl.NumberFormat API support, this method simply calls Intl.NumberFormat.
developer.mozilla.org
2. 함수로 만들기
const displayComma = (num: number) => {
return Number(num).toLocaleString() || ''
}
복사해서 가져다 쓰세요.
728x90
'자바스크립트' 카테고리의 다른 글
배열의 값을 더해야 할 때 (0) | 2023.03.15 |
---|---|
자바스크립트 날짜바꾸기 (0) | 2023.03.14 |
자바스크립트 우편번호가 1234567로 왔을 때 하이픈추가하기 (0) | 2023.03.14 |
스크립트 < script> (0) | 2022.05.01 |
주석 단축키 (0) | 2022.04.21 |