标签:
float转string
带千位符 ( 逗号 )
默认为.2f格式,需要其他请自行修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
- (NSString*) numberToMathString:( float ) num
{ NSArray * array = [[NSString stringWithFormat:@ "%.2f" ,num/100] componentsSeparatedByString:@ "." ];
int
len = [array[0] length]; int
x = len%3; int
y = len/3; int
dotNumber = y; if
(x == 0) {
dotNumber -= 1;
x = 3;
}
NSMutableString * rs = [@ ""
mutableCopy]; [rs appendString:[array[0] substringWithRange:NSMakeRange(0, x)]];
for
( int
i=0; i<dotNumber; i++) {
[rs appendString:@ "," ];
[rs appendString:[array[0] substringWithRange:NSMakeRange(x + i*3, 3)]];
}
[rs appendString:@ "." ];
[rs appendString:array[1]];
return
rs; } |
标签:
原文地址:http://blog.csdn.net/u014311042/article/details/42389201