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

前端 未结 4 1959
栀梦
栀梦 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条回答
  •  猫巷女王i
    2021-01-02 14:52

    In this case it is looking for a format NSString. Look here for format string details.

    If you want the negative of 12,345.67 to display as -12,345.67, then I believe the correct NSString value is @"-#,##0.00"

    I also noted the following sentence in the document linked above:

    If you don’t specify a format for negative values, the format specified for positive values is used, preceded by a minus sign (-).

    EDIT:
    Update for 10.4 and after: Here is a PDF describing behavior in 10.4 and after
    And, as linked from that document, here is the data on the required format for 10.4 and after.
    From this document, it appears the correct string may be: @"-#,##0.##"

提交回复
热议问题