Search code examples
swiftmacoscocoansnumberformatter

custom number formatter with currency symbol


I have a text field where the user should be enter a price. On this text field I dragged a Custom Number Formatter with this settings:

enter image description here

This works nearly perfect but I have a problem with the "Format". At the moment it is: .#.##

But what I have to change to show automatically the correct user currency symbol at the end?


Solution

  • For the static solution you can simply change format from .#.## to .#.## €

    If you're looking for universal way to do it, you're interested with symbol ¤, which is responsible for currency sign.

    So the format which are you looking for is ,#.## ¤

    Last step is to check option lenient, otherwise you need to provide full format in text field.

    More details

    Since OSX 10.9 and iOS 7 the format strings uses patterns from the Unicode Technical Standard #35 of version 31.

    You can find all number format patterns in this version here

    Apple documentation about number formatters