본문 바로가기
Android/Android 핵심기술

[Android/Kotlin] 천단위로 콤마 표시하기 (DecimalFormat)

by juwon2 2024. 4. 12.

 

1) 숫자 천단위 콤마

DecimalFormat을 사용해서 #,###으로 3자리마다 콤마가 찍히도록 설정해주었다
format 괄호 안에는 적용시킬 데이터를 넣어주면된다

DecimalFormat("#,###").format(123456)
// 123,456

 
 
 

2) 숫자 천단위 콤마, 소숫점 00으로 고정

DecimalFormat("#,###.00").format(123456)
// 123,456.00

 
 
 

3) 숫자 천단위 콤마, 소숫점 두자리까지만 표시

DecimalFormat("#,###.##").format(123456.1234)
// 123,456.12

 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 참고자료
https://skogkatt.tistory.com/entry/Kotlin-%EC%BD%94%ED%8B%80%EB%A6%B0-DecimalFormat-%EC%B2%9C%EB%8B%A8%EC%9C%84-%EC%BD%A4%EB%A7%88-%EC%86%8C%EC%88%AB%EC%A0%90-%EB%84%A3%EA%B8%B0

 

[Kotlin] 코틀린 DecimalFormat / 천단위 콤마, 소숫점 넣기

[Kotlin] 코틀린 DecimalFormat / 천단위 콤마 넣기 val dec = DecimalFormat("#,###") var test = 123456 dec.format(test) // 123,456 소숫점 항상 표시 val dec = DecimalFormat("#,###.00") var test = 123456 dec.format(test) // 123,456.00 https://s

skogkatt.tistory.com

https://minchanyoun.tistory.com/61

 

[Android][kotlin] DecimalFormat / 숫자 천 단위 콤마, 소숫점 넣기

오늘은 숫자 천 단위 콤마를 찍어 숫자를 표시하는 방법에 대해서 알아보겠습니다. CASE 1. 숫자 천 단위 콤마 //숫자 천 단위 콤마 val decimal = DecimalFormat("#,###") var testNum = 123456 decimal.format(testNum) //1

minchanyoun.tistory.com