45 lines
1.2 KiB
Twig
45 lines
1.2 KiB
Twig
{%- import 'macroses/common.utils.twig' as utils -%}
|
|
|
|
import LeadKit
|
|
import Foundation
|
|
|
|
public enum ApiNumberFormat: NumberFormat {
|
|
|
|
case decimal
|
|
|
|
public var numberFormatter: NumberFormatter {
|
|
let numberFormatter = NumberFormatter()
|
|
numberFormatter.decimalSeparator = "."
|
|
numberFormatter.minimumIntegerDigits = 1
|
|
numberFormatter.maximumFractionDigits = 16
|
|
|
|
return numberFormatter
|
|
}
|
|
}
|
|
|
|
public final class ApiNumberFormattingService: NumberFormattingService, Singleton {
|
|
|
|
public typealias NumberFormatType = ApiNumberFormat
|
|
|
|
public static let shared = ApiNumberFormattingService()
|
|
|
|
public let formatters = computedFormatters
|
|
|
|
private init() {}
|
|
|
|
public func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? {
|
|
guard let number = number(from: string, format: format) else {
|
|
return nil
|
|
}
|
|
return NSDecimalNumber(decimal: number.decimalValue)
|
|
}
|
|
}
|
|
|
|
extension ApiNumberFormattingService {
|
|
|
|
public static func decimalNumber(from string: String, format: ApiNumberFormat) -> NSDecimalNumber? {
|
|
return shared.decimalNumber(from: string, format: format)
|
|
}
|
|
}
|
|
|
|
{{ "\n" }} |