很简单,一个方法搞定
+(NSString *)changeFloat:(NSString *)stringFloat
{
const char *floatChars = [stringFloat UTF8String];
NSUInteger length = [stringFloat length];
NSUInteger zeroLength = 0;
int i = length-1;
for(; i>=0; i--)
{
if(floatChars[i] == '0'/*0x30*/) {
zeroLength++;
} else {
if(floatChars[i] == '.')
i--;
break;
}
}
NSString *returnString;
if(i == -1) {
returnString = @"0";
} else {
returnString = [stringFloat substringToIndex:i+1];
}
return returnString;
}