Merge pull request #3740 from eviltofu/3531_Override_Locale_Number_Formatting
Removed unused Formatters, CurrencyFormatter and other NumberFormatters replaced with Formatters #3531pull/3758/head
commit
90820dfb6f
@ -1,84 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
|
||||
extension NumberFormatter { |
||||
|
||||
static let currency = Formatter(.currency) |
||||
static let usd = Formatter(.usd(format: .withTrailingCurrency)) |
||||
static let percent = Formatter(.percent) |
||||
static let shortCrypto = Formatter(.shortCrypto) |
||||
|
||||
static func usd(format: USDFormat) -> Formatter { |
||||
Formatter(.usd(format: format)) |
||||
} |
||||
|
||||
class Formatter { |
||||
private let formatter: NumberFormatter |
||||
|
||||
fileprivate init(_ configuration: NumberFormatterConfiguration) { |
||||
formatter = configuration.formatter |
||||
} |
||||
|
||||
func string(from number: Double) -> String? { |
||||
return formatter.string(from: number as NSNumber) |
||||
} |
||||
} |
||||
} |
||||
|
||||
enum USDFormat { |
||||
case withTrailingCurrency |
||||
case withLeadingCurrencySymbol(positiveSymbol: String) |
||||
|
||||
static var priceChangeFormat: USDFormat { |
||||
.withLeadingCurrencySymbol(positiveSymbol: "+") |
||||
} |
||||
|
||||
static var fiatFormat: USDFormat { |
||||
.withLeadingCurrencySymbol(positiveSymbol: "") |
||||
} |
||||
} |
||||
|
||||
private enum NumberFormatterConfiguration { |
||||
case usd(format: USDFormat) |
||||
case currency |
||||
case percent |
||||
case shortCrypto |
||||
|
||||
var formatter: NumberFormatter { |
||||
let formatter = NumberFormatter() |
||||
formatter.roundingMode = .down |
||||
formatter.numberStyle = .currency |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
|
||||
switch self { |
||||
case .currency: |
||||
//TODO support multiple currency values |
||||
formatter.currencyCode = Currency.USD.rawValue |
||||
case .usd(let format): |
||||
switch format { |
||||
case .withTrailingCurrency: |
||||
formatter.positiveFormat = "0.00" + " " + Constants.Currency.usd |
||||
formatter.negativeFormat = "-0.00" + " " + Constants.Currency.usd |
||||
case .withLeadingCurrencySymbol(let positiveSymbol): |
||||
formatter.positiveFormat = positiveSymbol + "$0.00" |
||||
formatter.negativeFormat = "-$0.00" |
||||
} |
||||
|
||||
formatter.currencyCode = String() |
||||
case .percent: |
||||
formatter.positiveFormat = "0.00" |
||||
formatter.negativeFormat = "-0.00" |
||||
formatter.numberStyle = .percent |
||||
case .shortCrypto: |
||||
formatter.positiveFormat = "0.0000" |
||||
formatter.negativeFormat = "-0.0000" |
||||
formatter.numberStyle = .none |
||||
formatter.minimumFractionDigits = Constants.etherFormatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.etherFormatterFractionDigits |
||||
} |
||||
|
||||
return formatter |
||||
} |
||||
} |
@ -1,67 +0,0 @@ |
||||
// Copyright SIX DAY LLC. All rights reserved. |
||||
|
||||
import Foundation |
||||
|
||||
final class DecimalFormatter { |
||||
var groupingSeparator: String { |
||||
return numberFormatter.groupingSeparator |
||||
} |
||||
/// Locale of a `DecimalFormatter`. |
||||
var locale: Locale |
||||
/// numberFormatter of a `DecimalFormatter` to represent current locale. |
||||
private lazy var numberFormatter: NumberFormatter = { |
||||
let formatter = NumberFormatter() |
||||
formatter.locale = locale |
||||
formatter.numberStyle = .decimal |
||||
formatter.isLenient = true |
||||
return formatter |
||||
}() |
||||
/// usFormatter of a `DecimalFormatter` to represent decimal separator ".". |
||||
private lazy var usFormatter: NumberFormatter = { |
||||
let formatter = NumberFormatter() |
||||
formatter.locale = Locale(identifier: "en_US") |
||||
formatter.numberStyle = .decimal |
||||
formatter.isLenient = true |
||||
return formatter |
||||
}() |
||||
/// frFormatter of a `DecimalFormatter` to represent decimal separator ",". |
||||
private lazy var frFormatter: NumberFormatter = { |
||||
let formatter = NumberFormatter() |
||||
formatter.locale = Locale(identifier: "fr_FR") |
||||
formatter.numberStyle = .decimal |
||||
formatter.isLenient = true |
||||
return formatter |
||||
}() |
||||
/// enCaFormatter of a `DecimalFormatter` to represent decimal separator "'". |
||||
private lazy var enCaFormatter: NumberFormatter = { |
||||
let formatter = NumberFormatter() |
||||
formatter.locale = Locale(identifier: "en_CA") |
||||
formatter.numberStyle = .decimal |
||||
formatter.isLenient = true |
||||
return formatter |
||||
}() |
||||
/// Initializes a `DecimalFormatter` with a `Locale`. |
||||
init(locale: Locale = Config.locale) { |
||||
self.locale = locale |
||||
self.numberFormatter = NumberFormatter() |
||||
self.numberFormatter.locale = self.locale |
||||
self.numberFormatter.numberStyle = .decimal |
||||
self.numberFormatter.isLenient = true |
||||
} |
||||
/// Converts a String to a `NSNumber`. |
||||
/// |
||||
/// - Parameters: |
||||
/// - string: string to convert. |
||||
/// - Returns: `NSNumber` representation. |
||||
func number(from string: String) -> NSNumber? { |
||||
return numberFormatter.number(from: string) ?? usFormatter.number(from: string) ?? frFormatter.number(from: string) ?? enCaFormatter.number(from: string) |
||||
} |
||||
/// Converts a NSNumber to a `String`. |
||||
/// |
||||
/// - Parameters: |
||||
/// - number: NSNumber to convert. |
||||
/// - Returns: `NSumber` representation. |
||||
func string(from number: NSNumber) -> String? { |
||||
return numberFormatter.string(from: number) |
||||
} |
||||
} |
@ -0,0 +1,124 @@ |
||||
// |
||||
// Formatters.swift |
||||
// AlphaWallet |
||||
// |
||||
// Created by Jerome Chan on 17/1/22. |
||||
// |
||||
|
||||
import Foundation |
||||
|
||||
struct Formatter { |
||||
|
||||
static let currency: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.currencySymbol = "$" |
||||
return formatter |
||||
}() |
||||
|
||||
static let usd: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.positiveFormat = ",###.# " + Constants.Currency.usd |
||||
formatter.negativeFormat = "-,###.# " + Constants.Currency.usd |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
return formatter |
||||
}() |
||||
|
||||
static let percent: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.positiveFormat = ",###.#" |
||||
formatter.negativeFormat = "-,###.#" |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.numberStyle = .percent |
||||
return formatter |
||||
}() |
||||
|
||||
static let shortCrypto: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.positiveFormat = ",###.#" |
||||
formatter.negativeFormat = "-,###.#" |
||||
formatter.minimumFractionDigits = Constants.etherFormatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.etherFormatterFractionDigits |
||||
formatter.numberStyle = .none |
||||
return formatter |
||||
}() |
||||
|
||||
static let priceChange: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.positiveFormat = "+$,###.#" |
||||
formatter.negativeFormat = "-$,###.#" |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
return formatter |
||||
}() |
||||
|
||||
static let fiat: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.positiveFormat = "$,###.#" |
||||
formatter.negativeFormat = "-$,###.#" |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
return formatter |
||||
}() |
||||
|
||||
static let `default`: NumberFormatter = { |
||||
let formatter = NumberFormatter() |
||||
return formatter |
||||
}() |
||||
|
||||
static let scientificAmount: NumberFormatter = { |
||||
let formatter = Formatter.default |
||||
formatter.numberStyle = .decimal |
||||
formatter.usesGroupingSeparator = false |
||||
return formatter |
||||
}() |
||||
|
||||
static let currencyAccounting: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.currencySymbol = "" |
||||
formatter.minimumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.formatterFractionDigits |
||||
formatter.numberStyle = .currencyAccounting |
||||
formatter.isLenient = true |
||||
return formatter |
||||
}() |
||||
|
||||
static let alternateAmount: NumberFormatter = { |
||||
let formatter = basicCurrencyFormatter() |
||||
formatter.currencySymbol = "" |
||||
formatter.minimumFractionDigits = Constants.etherFormatterFractionDigits |
||||
formatter.maximumFractionDigits = Constants.etherFormatterFractionDigits |
||||
return formatter |
||||
}() |
||||
} |
||||
|
||||
fileprivate func basicCurrencyFormatter() -> NumberFormatter { |
||||
let formatter = basicNumberFormatter() |
||||
formatter.numberStyle = .currency |
||||
formatter.roundingMode = .down |
||||
return formatter |
||||
} |
||||
|
||||
fileprivate func basicNumberFormatter() -> NumberFormatter { |
||||
let formatter = NumberFormatter() |
||||
formatter.locale = Locale(identifier: "en_US") |
||||
formatter.generatesDecimalNumbers = true |
||||
formatter.alwaysShowsDecimalSeparator = true |
||||
formatter.usesGroupingSeparator = true |
||||
formatter.isLenient = false |
||||
formatter.isPartialStringValidationEnabled = false |
||||
formatter.groupingSeparator = "," |
||||
formatter.decimalSeparator = "." |
||||
return formatter |
||||
} |
||||
|
||||
extension NumberFormatter { |
||||
|
||||
func string(from source: Double) -> String? { |
||||
return self.string(from: source as NSNumber) |
||||
} |
||||
|
||||
} |
@ -0,0 +1,165 @@ |
||||
// |
||||
// FormattersTests.swift |
||||
// AlphaWalletTests |
||||
// |
||||
// Created by Jerome Chan on 19/1/22. |
||||
// |
||||
|
||||
@testable import AlphaWallet |
||||
import XCTest |
||||
|
||||
class FormattersTestCase: XCTestCase { |
||||
|
||||
func testCurrency() { |
||||
XCTAssertEqual(Formatter.currency.string(from: 0.0)!, "$0.00") |
||||
XCTAssertEqual(Formatter.currency.string(from: 10.100)!, "$10.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: 100.105)!, "$100.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: 1000.109)!, "$1,000.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: 9999999999999.999)!, "$9,999,999,999,999.99") |
||||
XCTAssertEqual(Formatter.currency.string(from: -0.0)!, "-$0.00") |
||||
XCTAssertEqual(Formatter.currency.string(from: -10.100)!, "-$10.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: -100.105)!, "-$100.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: -1000.109)!, "-$1,000.10") |
||||
XCTAssertEqual(Formatter.currency.string(from: -9999999999999.999)!, "-$9,999,999,999,999.99") |
||||
// XCTAssertEqual(Formatters.currency.string(from: 123456789123456789.056), "$123,456,789,123,456,789.05") |
||||
} |
||||
|
||||
func testUsd() { |
||||
XCTAssertEqual(Formatter.usd.string(from: 0.0)!, "0.00 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: 10.100)!, "10.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: 100.105)!, "100.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: 1000.109)!, "1,000.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: 9999999999999.999)!, "9,999,999,999,999.99 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: -0.0)!, "-0.00 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: -10.100)!, "-10.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: -100.105)!, "-100.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: -1000.109)!, "-1,000.10 USD") |
||||
XCTAssertEqual(Formatter.usd.string(from: -9999999999999.999)!, "-9,999,999,999,999.99 USD") |
||||
} |
||||
|
||||
func testPercent() { |
||||
XCTAssertEqual(Formatter.percent.string(from: 0.0)!, "0.00") |
||||
XCTAssertEqual(Formatter.percent.string(from: 10.100)!, "10.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: 100.105)!, "100.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: 1000.109)!, "1,000.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: 9999999999999.999)!, "9,999,999,999,999.99") |
||||
XCTAssertEqual(Formatter.percent.string(from: -0.0)!, "-0.00") |
||||
XCTAssertEqual(Formatter.percent.string(from: -10.100)!, "-10.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: -100.105)!, "-100.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: -1000.109)!, "-1,000.10") |
||||
XCTAssertEqual(Formatter.percent.string(from: -9999999999999.999)!, "-9,999,999,999,999.99") |
||||
} |
||||
|
||||
func testShortCrypto() { |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: 0.0)!, "0.0000") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: 10.100)!, "10.1000") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: 100.105)!, "100.1050") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: 1000.109)!, "1,000.1090") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: 999999999999.999)!, "999,999,999,999.9990") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: -0.0)!, "-0.0000") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: -10.100)!, "-10.1000") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: -100.105)!, "-100.1050") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: -1000.109)!, "-1,000.1090") |
||||
XCTAssertEqual(Formatter.shortCrypto.string(from: -999999999999.999)!, "-999,999,999,999.9990") |
||||
} |
||||
|
||||
func testPriceChange() { |
||||
XCTAssertEqual(Formatter.priceChange.string(from: 0.0)!, "+$0.00") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: 10.100)!, "+$10.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: 100.105)!, "+$100.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: 1000.109)!, "+$1,000.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: 9999999999999.999)!, "+$9,999,999,999,999.99") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: -0.0)!, "-$0.00") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: -10.100)!, "-$10.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: -100.105)!, "-$100.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: -1000.109)!, "-$1,000.10") |
||||
XCTAssertEqual(Formatter.priceChange.string(from: -9999999999999.999)!, "-$9,999,999,999,999.99") |
||||
} |
||||
|
||||
func testFiat() { |
||||
XCTAssertEqual(Formatter.fiat.string(from: 0.0)!, "$0.00") |
||||
XCTAssertEqual(Formatter.fiat.string(from: 10.100)!, "$10.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: 100.105)!, "$100.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: 1000.109)!, "$1,000.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: 9999999999999.999)!, "$9,999,999,999,999.99") |
||||
XCTAssertEqual(Formatter.fiat.string(from: -0.0)!, "-$0.00") |
||||
XCTAssertEqual(Formatter.fiat.string(from: -10.100)!, "-$10.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: -100.105)!, "-$100.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: -1000.109)!, "-$1,000.10") |
||||
XCTAssertEqual(Formatter.fiat.string(from: -9999999999999.999)!, "-$9,999,999,999,999.99") |
||||
} |
||||
|
||||
func testDefault() { |
||||
XCTAssertEqual(Formatter.default.string(from: 0.0)!, "0") |
||||
XCTAssertEqual(Formatter.default.string(from: 10.1)!, "10") |
||||
XCTAssertEqual(Formatter.default.string(from: 100.50)!, "100") |
||||
XCTAssertEqual(Formatter.default.string(from: 100.51)!, "101") |
||||
XCTAssertEqual(Formatter.default.string(from: 1000.9)!, "1001") |
||||
XCTAssertEqual(Formatter.default.string(from: 9999999999999.999)!, "10000000000000") |
||||
XCTAssertEqual(Formatter.default.string(from: -0.0)!, "-0") |
||||
XCTAssertEqual(Formatter.default.string(from: -10.1)!, "-10") |
||||
XCTAssertEqual(Formatter.default.string(from: -100.50)!, "-100") |
||||
XCTAssertEqual(Formatter.default.string(from: -100.51)!, "-101") |
||||
XCTAssertEqual(Formatter.default.string(from: -1000.9)!, "-1001") |
||||
XCTAssertEqual(Formatter.default.string(from: -9999999999999.999)!, "-10000000000000") |
||||
} |
||||
|
||||
func testStringCurrency() { |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 0.0)!, "0.00") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 0.500)!, "0.50") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 0.505)!, "0.50") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 0.509)!, "0.50") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 1000.50)!, "1,000.50") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: 9999999999999.999)!, "9,999,999,999,999.99") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -0.0)!, "(0.00)") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -0.500)!, "(0.50)") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -0.505)!, "(0.50)") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -0.509)!, "(0.50)") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -1000.50)!, "(1,000.50)") |
||||
XCTAssertEqual(Formatter.currencyAccounting.string(from: -9999999999999.999)!, "(9,999,999,999,999.99)") |
||||
} |
||||
|
||||
func testAlternateAmount() { |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.0)!, "0.0000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.5)!, "0.5000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.05)!, "0.0500") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.005)!, "0.0050") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.0005)!, "0.0005") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 0.00005)!, "0.0000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: 12341234.12345)!, "12,341,234.1234") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.0)!, "-0.0000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.5)!, "-0.5000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.05)!, "-0.0500") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.005)!, "-0.0050") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.0005)!, "-0.0005") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -0.00005)!, "-0.0000") |
||||
XCTAssertEqual(Formatter.alternateAmount.string(from: -12341234.12345)!, "-12,341,234.1234") |
||||
} |
||||
|
||||
func testScientificAmount() { |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 0.0)!, "0") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 0 as NSNumber)!, "0") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 1.0)!, "1") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 10.0)!, "10") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 100.0)!, "100") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 1000.0)!, "1000") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 12345.0)!, "12345") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 12345.49)!, "12345.49") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 12345.50)!, "12345.5") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: 12345.51)!, "12345.51") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -0.0)!, "-0") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -0 as NSNumber)!, "0") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -1.0)!, "-1") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -10.0)!, "-10") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -100.0)!, "-100") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -1000.0)!, "-1000") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -12345.0)!, "-12345") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -12345.49)!, "-12345.49") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -12345.50)!, "-12345.5") |
||||
XCTAssertEqual(Formatter.scientificAmount.string(from: -12345.51)!, "-12345.51") |
||||
XCTAssertEqual(Formatter.scientificAmount.number(from: "1.25E+12")!, 1.25E12) |
||||
XCTAssertEqual(Formatter.scientificAmount.number(from: "-1.25E+12")!, -1.25E12) |
||||
XCTAssertEqual(Formatter.scientificAmount.number(from: "1.25E-12")!, 1.25E-12) |
||||
XCTAssertEqual(Formatter.scientificAmount.number(from: "-1.25E-12")!, -1.25E-12) |
||||
} |
||||
} |
Loading…
Reference in new issue