-
[코틀린] DecimalFormat을 이용한 3자리마다 콤마 넣기카테고리 없음 2024. 4. 15. 18:44
사용법
DecimalFormat을 이용하여 확장함수를 만들어 숫자 클래스에서 사용할 수 있게 만들어주었다.
#,###으로 3자리마다 콤마를 넣어주었고 .###으로 3자리의 소수점만 보이도록 하였다.
private val decimalFormat = DecimalFormat("#,###.###") internal fun Double.applyComma(): String = decimalFormat.format(this) internal fun Long.applyComma(): String = decimalFormat.format(this) internal fun Int.applyComma(): String = decimalFormat.format(this)
실행결과