Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- ubuntu
- GIT
- sqlite
- tensorflow
- 맛집
- PyQt
- urllib
- Excel
- 라즈베리파이
- 다이어트
- MySQL
- 함수
- pandas
- 유니티
- PER
- swift
- port
- javascript
- PyQt5
- 리눅스
- ASP
- python
- Unity
- IOS
- Linux
- mssql
- MS-SQL
- 날짜
- flutter
- node.js
Archives
아미(아름다운미소)
Swift 숫자값을 3자리 단위로 콤마(,)를 추가 본문
가끔 숫자값을 3자리 단위로 콤마(,)를 추가하여 자릿수를 구분해주는 기능이 필요할 경우
extension Int { var withComma: String { let decimalFormatter = NumberFormatter() decimalFormatter.numberStyle = NumberFormatter.Style.decimal decimalFormatter.groupingSeparator = "," decimalFormatter.groupingSize = 3 return decimalFormatter.string(from: self as NSNumber)! } } extension String { var delComma: String { if self.characters.count > 0 { return self.replacingOccurrences(of: ",", with: "") } else { return "0" } } }사용하기
let a: String = (123456789).withComma let b: String = a.delComma let c: String = "123,45a".delComma
'랭귀지 > SWIFT' 카테고리의 다른 글
nil 전달 함수 (0) | 2018.02.09 |
---|---|
IOS(Swift) HTTP접근 허용 NSAppTransportSecurity (0) | 2018.02.08 |
[iOS : Swift] Segue 코드상으로 연결하는 방법 (0) | 2018.02.06 |
JSON 문자열을 Dictionary로 변환 (0) | 2018.02.04 |
페이지 이동하기 - 페이지 컨트롤 (0) | 2018.02.03 |
Comments