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.
61 lines
1.4 KiB
61 lines
1.4 KiB
//
|
|
// Formatters.swift
|
|
// TournamentStats
|
|
//
|
|
// Created by Laurent Morvillier on 03/06/2019.
|
|
// Copyright © 2019 Stax River. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class Formatter {
|
|
|
|
static var currency: NumberFormatter {
|
|
let c = NumberFormatter()
|
|
c.locale = Locale(identifier: "en_US")
|
|
c.usesGroupingSeparator = true
|
|
c.groupingSeparator = ","
|
|
c.decimalSeparator = "."
|
|
c.currencySymbol = "$"
|
|
c.maximumFractionDigits = 0
|
|
c.numberStyle = .currency
|
|
return c
|
|
}
|
|
|
|
static var importData: NumberFormatter {
|
|
let formatter = NumberFormatter()
|
|
formatter.usesGroupingSeparator = true
|
|
formatter.groupingSeparator = ","
|
|
formatter.decimalSeparator = "."
|
|
formatter.numberStyle = .decimal
|
|
return formatter
|
|
}
|
|
|
|
static var basicDate: DateFormatter {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "dd/MM/yyyy"
|
|
return formatter
|
|
}
|
|
|
|
static var fileDate: DateFormatter {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "yyyy_MM_dd"
|
|
return formatter
|
|
}
|
|
|
|
}
|
|
|
|
extension Int {
|
|
|
|
var currencyFormatted: String {
|
|
return Formatter.currency.string(from: NSNumber(value: self)) ?? ""
|
|
}
|
|
}
|
|
|
|
extension Double {
|
|
|
|
var currencyFormatted: String {
|
|
return Formatter.currency.string(from: NSNumber(value: self)) ?? ""
|
|
}
|
|
|
|
}
|
|
|