Double

public extension Double

Double+CurrencyFormattable is used to format a number into currency string.

Author

Adamas

Version

1.8.0

Date

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

    numberFormatter

    The 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

    numberFormatter

    The 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

    shouldDisplayCent

    Whether the cent should be displayed or not. Nil will apply the cent dynamically.

    numberFormatter

    The number formatter to use.

    Return Value

    The formatted string.

  • Read a currency string.

    Declaration

    Swift

    init?(currency: String,
          numberFormatter: NumberFormatter = Self.defaultCurrencyFormatter)

    Parameters

    currency

    The string to be rendered.

    numberFormatter

    The 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

    precision

    The 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

    numberFormatter

    The number formatter applied.

    Return Value

    The long number string.

  • Read a long number string.

    Declaration

    Swift

    init?(longNumber: String)

    Parameters

    longNumber

    The 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

    precision

    The precision spedified. If it is nil, the precision will be default to 2 digits.

    numberFormatter

    The number formatter used.

    Return Value

    The formatted string.

  • Read a percent string.

    Declaration

    Swift

    init?(percentage: String)

    Parameters

    percentage

    The string to be rendered.

  • The distance string presenting the distance.

    Declaration

    Swift

    func distanceString(withPrecision precision: Int? = nil, withAbbr shouldUseAbbr: Bool = true) -> String

    Parameters

    precision

    The precision of the string.

    shouldUseAbbr

    Whether the unit should be abbr or not.

    Return Value

    The distance streen