Double
public extension Double
Double+CurrencyFormattable is used to format a number into currency string.
Version
1.8.0Date
28/04/2022-
Default currency formatter
Declaration
Swift
static let defaultCurrencyFormatter: NumberFormatter -
Get the cent part of the currency string
Declaration
Swift
func centString(numberFormatter: NumberFormatter = Self.defaultCurrencyFormatter) -> String?Parameters
numberFormatterThe number formatter to use.
Return Value
The cent string
-
Get the dollar part of the currency string
Declaration
Swift
func dollarString(numberFormatter: NumberFormatter = Self.defaultCurrencyFormatter) -> String?Parameters
numberFormatterThe number formatter to use.
Return Value
The dollar string
-
Print the number as a string using money format. For example, $1,000,000.00.
Declaration
Swift
func currencyString(withCent shouldDisplayCent: Bool? = nil, numberFormatter: NumberFormatter = Self.defaultCurrencyFormatter) -> String?Parameters
shouldDisplayCentWhether the cent should be displayed or not. Nil will apply the cent dynamically.
numberFormatterThe number formatter to use.
Return Value
The formatted string.
-
Read a currency string.
Declaration
Swift
init?(currency: String, numberFormatter: NumberFormatter = Self.defaultCurrencyFormatter)Parameters
currencyThe string to be rendered.
numberFormatterThe number format used to detect the currency string
-
Print the decimal number with specific precision. For example, 12.3.
Declaration
Swift
func decimalString(withPrecision precision: Int? = nil) -> String?Parameters
precisionThe precision spedified. If it is nil, the original value will be returned.
Return Value
The formatted string.
-
Default long number formatter
Declaration
Swift
static let longNumberFormatter: NumberFormatter -
Format the number into a readable number format.
Declaration
Swift
func longNumberString(numberFormatter: NumberFormatter = Self.longNumberFormatter) -> String?Parameters
numberFormatterThe number formatter applied.
Return Value
The long number string.
-
Read a long number string.
Declaration
Swift
init?(longNumber: String)Parameters
longNumberThe string to be rendered.
-
Round up the double to an integer.
Declaration
Swift
var roundedUp: Int { get } -
Undocumented
Declaration
Swift
static let defaultPercentageFormatter: NumberFormatter -
Print the number as a percentage. For example, 12.3%.
Declaration
Swift
func percentageString(withPrecision precision: Int? = nil, numberFormatter: NumberFormatter = Self.defaultPercentageFormatter) -> String?Parameters
precisionThe precision spedified. If it is nil, the precision will be default to 2 digits.
numberFormatterThe number formatter used.
Return Value
The formatted string.
-
Read a percent string.
Declaration
Swift
init?(percentage: String)Parameters
percentageThe string to be rendered.
-
The distance string presenting the distance.
Declaration
Swift
func distanceString(withPrecision precision: Int? = nil, withAbbr shouldUseAbbr: Bool = true) -> StringParameters
precisionThe precision of the string.
shouldUseAbbrWhether the unit should be abbr or not.
Return Value
The distance streen
Double Extension Reference