How to specify decimal places when formatting NSNumber objects?

前端 未结 3 933
时光取名叫无心
时光取名叫无心 2020-12-31 15:12

I\'m using the following piece of Objective-C code to format a NSNumber, and it works fine most of the time, but it doesn\'t quite do what I want when the NSNumber object ho

3条回答
  •  滥情空心
    2020-12-31 16:00

    I believe what you are looking for is: "%.2f"

    Worst case scenario, you can split the value, check if there is anything after the decimal. If there isn't add the 00 by hand?

提交回复
热议问题