「iphone開発」数値float型から文字列値への変換する方法

コード下記:
– (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;
}

IOS

Posted by arkgame