Swift Package Index


Swift FractionFormatter, like NumberFormatter, but outputs fractions.


  • The latest stable release is 0.9.0. Released 12 days ago.
  • The last commit to main was 12 days ago.

Swift Version Compatibility

  • 0.9.0 and main
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.9.0 and main
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

FractionFormatter

A simple extention to number formatter that outputs pretty printed Unicode fractions rather than decimal.

let fractionFormatter = FractionFormatter()
fractionFormatter.string(from: NSNumber(value: 0.5)) // ½
fractionFormatter.string(from: NSNumber(value: 0.123)) // ¹²³⁄₁₀₀₀

Known Issues

Radar FB7644708 - Pluarlization and number formatting

When combined with Apple's MeasurementFormatter there are issues with pluralization. For example, using the built in NumberFormatter to format fractional feet, it will output "0.5 feet", read as "zero point five feet", but if you substitute FractionFormatter then the output is "½ feet", which is not how it is normally written in English. Normally we say "half a foot", or more formally "one half of a foot" and thus write the signular form.

The workaround it to pull the symbol from the measurement and substitue the pluralized symbol when the measurement is between -1 and 1.