Contents

formatted(_:)

Formats the decimal using the provided format style.

Declaration

func formatted<S>(_ format: S) -> S.FormatOutput where S : FormatStyle, S.FormatInput == Decimal

Parameters

  • format:

    The format style to apply when formatting the decimal.

Return Value

A localized, formatted string representation of the decimal.

Discussion

Use this method when you want to format a single decimal value with a specific format style or multiple format styles. The following example shows the results of formatting a given decimal value with format styles for the en_US and fr_FR locales:

let decimal: Decimal = 123456.789
let usStyle = Decimal.FormatStyle(locale: Locale(identifier: "en_US"))
let frStyle = Decimal.FormatStyle(locale: Locale(identifier: "fr_FR"))
let formattedUS = decimal.formatted(usStyle) // 123,456.789
let formattedFR = decimal.formatted(frStyle) // 123 456,789

See Also

Formatting decimals