How to format a double Value upto 2 decimal places in iPhone

前端 未结 3 1179
长情又很酷
长情又很酷 2020-12-20 04:20

I am extracting double data from sqlite3 database. But I want to display it only upto two decimal places. So how to truncate it.

相关标签:
3条回答
  • 2020-12-20 04:47

    Use sprintf formatting with NSString: [NSString stringWithFormat: @"%.2f", myValue];

    0 讨论(0)
  • 2020-12-20 04:52

    Ah, Ben beat me to it! You might also find this http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html useful.

    0 讨论(0)
  • 2020-12-20 05:04

    See NSNumberFormatter. It formats numbers.

    0 讨论(0)
提交回复
热议问题