How to format percent in Swift
Issue #639
Never use String(format: "%.2f %%", 1.2 because each region can have different separator and placement of percent sign.
Use NumberFormatter instead
1 | let formatter = NumberFormatter() |
1 | formatter.locale = Locale(identifier: "en_US") |
Note that the space created by NumberFormatter is a non breakable space \u{00a0}, which can be created by Alt Space. This non breakable space is useful in UILabel when you want the whole word to stick together