Numerical FormatStyles

This is part of the FormatStyle Deep Dive series

Every supported number type in Swift have identical support for numerical FormatStyles. Each one has the identical ability to be formatted as .number, .currency, and .percent.

NOTE: Please don’t use floating point numbers to store and modify currency vales. This storage type is not guaranteed to be free of rounding errors, and will cause long term grief.


Download the Xcode Playground with all examples

See the examples as a gist


.number

This is the general FormatStyle for numbers.

See the .number deep dive


.currency

A powerful style that handles the localization complexities of display currency values.

See the .currency deep dive


.percent

Handles the display of percentages

See the .percent deep dive


Download the Xcode Playground with all examples

See the examples as a gist


Tags: