/*
* Processing a string with a number plus a decimal point, preceded by 0, leaving two bits. There is a circular interception method on the Internet, if the number is too long and the memory is wasted, this method is designed on the basis of optimized memory.
*/
-(nsstring*) Getthecorrectnum: (nsstring*) tempstring
{
First judge is not. Is. Complement 0
if ([tempstring hasprefix:@ "."]) {
tempstring = [NSString stringwithformat:@ "0%@", tempstring];
}
Calculate the length of the Intercept
Nsuinteger endlength = tempstring.length;
Determines whether a string is contained.
if ([tempstring containsstring:@ "."]) {
Made. The location
Nsrange Pointrange = [tempstring rangeofstring:@ ".];
NSLog (@ "%lu", pointrange.location);
Judge. There are a few behind
Nsuinteger f = tempstring.length-1-pointrange.location;
If it is greater than 2 bits, the truncated string remains two bits, and if it is less than two bits, intercept directly
if (F > 2) {
Endlength = pointrange.location + 2;
}
}
Convert tempstring to char array first
Nsuinteger start = 0;
const char *tempchar = [tempstring utf8string];
Traverse, remove the position that gets the first digit not 0
for (int i = 0; i < tempstring.length; i++) {
if (tempchar[i] = = ' 0 ') {
start++;
}else {
Break
}
}
If the first letter is a. Start back one
if (tempchar[start] = = '. ') {
start--;
}
Calculates the length according to the final starting position, and intercepts
Nsrange range = {Start,endlength-start};
tempstring = [tempstring substringwithrange:range];
return tempstring;
}
Keep Two decimal places