NSString类型数据保留两位小数写法:
NSString *text = [NSString stringWithFormat:@"%@",cashBalance];
CGFloat floatValues = [text floatValue];
NSString *str = [NSString stringWithFormat:@"%.2f",floatValues];
_rightLabel.text = [NSString stringWithFormat:@"%@元",str];
设置数字与文字大小的写法
NSString *text1 = [NSString stringWithFormat:@"%@",cashBalance];
CGFloat floatValues1 = [text1 floatValue];
NSString *str1 = [NSString stringWithFormat:@"%.2f",floatValues1];
NSMutableAttributedString *frozenStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@元",str1]];
[frozenStr addAttribute:NSFontAttributeName value:kSystemFont_12 range:NSMakeRange(frozenStr.length - 1, 1)];
self.frozenLabel.attributedText = frozenStr;
本文介绍如何在iOS开发中使用NSString进行数值保留两位小数的格式化操作,并展示了如何利用NSAttributedString来设置字符串中特定部分的文字大小。

6531

被折叠的 条评论
为什么被折叠?



