Change NSNumberFormatter's negative format from (xxx.xx) to -xxx.xx

前端 未结 4 1944
栀梦
栀梦 2021-01-02 14:25

I want to change my NSNumberformatter from displaying negative numbers with parenthesis around them to putting the minus sign in front (or whatever the localized standard is

4条回答
  •  甜味超标
    2021-01-02 14:40

    If you take a look at the "Format Strings" section in the Data Formatting Programming Guide For Cocoa:

    The format string uses the format patterns from the Unicode Technical Standard #35 (this reference is to version tr35-6; formatters for Mac OS X v10.4 use version tr35-4).

    Edit:

    If you want to set a format string based on currencies, you can use the ¤ character, for example:

    [formatter setFormat:@"¤#,##0.00"];
    

    This will add the currency symbol for the current localization in place of the ¤ character.

    Therefore, applying the same concept to the negative format string:

    [formatter setFormat:@"-¤#,##0.00"];
    

    This will also apply the currency symbol in place of the ¤ for the current localization.

提交回复
热议问题