diff --git a/SodaLive/Sources/Extensions/StringExtension.swift b/SodaLive/Sources/Extensions/StringExtension.swift index b7e9f0f..099b5e1 100644 --- a/SodaLive/Sources/Extensions/StringExtension.swift +++ b/SodaLive/Sources/Extensions/StringExtension.swift @@ -44,4 +44,14 @@ extension String { // 출처 - https://ios-development.tistory.com/379 } + + func formatCurrency(currencyCode: String, locale: Locale = .current) -> String { + let formatter = NumberFormatter() + formatter.numberStyle = .currency + formatter.locale = locale + formatter.currencyCode = currencyCode + + let dec = NSDecimalNumber(string: self) + return formatter.string(from: dec) ?? "\(currencyCode) \(self)" + } } diff --git a/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift b/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift index 8348380..bdeec14 100644 --- a/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift +++ b/SodaLive/Sources/MyPage/Can/Charge/CanChargeView.swift @@ -124,7 +124,7 @@ struct CanPgItemView: View { Spacer() - Text("\(item.price) 원") + Text(item.priceStr.formatCurrency(currencyCode: item.currency)) .font(.custom(Font.bold.rawValue, size: 15.3)) .foregroundColor(Color(hex: "eeeeee")) } diff --git a/SodaLive/Sources/MyPage/Can/GetCanResponse.swift b/SodaLive/Sources/MyPage/Can/GetCanResponse.swift index 5faa378..c533ee5 100644 --- a/SodaLive/Sources/MyPage/Can/GetCanResponse.swift +++ b/SodaLive/Sources/MyPage/Can/GetCanResponse.swift @@ -13,4 +13,6 @@ struct GetCanResponse: Decodable, Hashable { let can: Int let rewardCan: Int let price: Int + let currency: String + let priceStr: String } diff --git a/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift b/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift index 4abfc1d..3bf5d85 100644 --- a/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift +++ b/SodaLive/Sources/MyPage/Can/Payment/CanPgPaymentView.swift @@ -117,7 +117,7 @@ struct CanPgPaymentView: View { Spacer() - Text("\(canResponse.price) 원") + Text(canResponse.priceStr.formatCurrency(currencyCode: canResponse.currency)) .font(.custom(Font.bold.rawValue, size: 15.3)) .foregroundColor(Color.grayee) } @@ -281,7 +281,7 @@ struct CanPgPaymentView: View { .foregroundColor(Color.grayee) HStack(spacing: 0) { - Text("\(canResponse.price) 원") + Text(canResponse.priceStr.formatCurrency(currencyCode: canResponse.currency)) .font(.custom(Font.bold.rawValue, size: 23.3)) .foregroundColor(Color.grayee) } @@ -378,7 +378,7 @@ struct CanPgPaymentView: View { struct CanPgPaymentView_Previews: PreviewProvider { static var previews: some View { CanPgPaymentView( - canResponse: GetCanResponse(id: 1, title: "300 캔", can: 300, rewardCan: 0, price: 7500), + canResponse: GetCanResponse(id: 1, title: "300 캔", can: 300, rewardCan: 0, price: 7500, currency: "USD", priceStr: "5.99"), refresh: {}, afterCompletionToGoBack: false )