Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 iOS 中显示浮点数,例如 .23
我见过人们不想要小数部分的问题。但我没有找到答案。我可以用 NSNumberFormatter 来做吗?我试图设置最小和最大整数位数,但没有用。有任何想法吗?
谢谢!!
我认为最好的方法是使用 NSNumberFormatter:
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setPositiveFormat:@"##.00"]; NSString* result = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:0.63f]];;