blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
7 years ago
|
// Copyright SIX DAY LLC. All rights reserved.
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
final class StringFormatter {
|
||
|
/// currencyFormatter of a `StringFormatter` to represent curent locale.
|
||
|
private lazy var currencyFormatter: NumberFormatter = {
|
||
|
let formatter = NumberFormatter()
|
||
|
formatter.currencySymbol = ""
|
||
|
formatter.minimumFractionDigits = 2
|
||
|
formatter.maximumFractionDigits = 2
|
||
|
formatter.numberStyle = .currencyAccounting
|
||
|
formatter.isLenient = true
|
||
|
return formatter
|
||
|
}()
|
||
|
/// Converts a Double to a `currency String`.
|
||
|
///
|
||
|
/// - Parameters:
|
||
|
/// - double: double to convert.
|
||
|
/// - currencyCode: code of the currency.
|
||
|
/// - Returns: Currency `String` represenation.
|
||
|
func currency(with value: Double, and currencyCode: String) -> String {
|
||
|
let formatter = currencyFormatter
|
||
|
formatter.currencyCode = currencyCode
|
||
|
return formatter.string(from: NSNumber(value: value)) ?? "\(value)"
|
||
|
}
|
||
|
/// Converts a Double to a `String`.
|
||
|
///
|
||
|
/// - Parameters:
|
||
|
/// - double: double to convert.
|
||
|
/// - precision: symbols after coma.
|
||
|
/// - Returns: `String` represenation.
|
||
|
func formatter(for double: Double, with precision: Int) -> String {
|
||
|
return String(format: "%.\(precision)f", double)
|
||
|
}
|
||
|
/// Converts a Double to a `String`.
|
||
|
///
|
||
|
/// - Parameters:
|
||
|
/// - double: double to convert.
|
||
|
/// - Returns: `String` represenation.
|
||
|
func formatter(for double: Double) -> String {
|
||
|
return String(format: "%f", double)
|
||
|
}
|
||
|
}
|