IOS returns a numeric string with no digits before the decimal point and two digits after the decimal point. ios decimal point
/** Process a string with a number plus a decimal point. There is no 0 before it, and two digits are retained. There is a method for loop Truncation on the Internet. If the number is too long and memory is wasted, this method is designed based on memory optimization. */-(NSString *) getTheCorrectNum :( NSString *) tempString {// first judge whether the first digit is ., yes. add 0 if ([tempString hasPrefix :@". "]) {tempString = [NSString stringWithFormat: @" 0% @ ", tempString];} // calculate the length of the intercepted NSUInteger endLength = tempString. length; // judge whether the string contains. if ([tempString containsString :@". "]) {// get. location of <G id = "1"> [tempString rangeOfString :@". "]; NSLog (@" % lu ", pointRange. location); // judge. there are several NSUInteger f = tempString. length-1-pointRange. location; // if the value is greater than two digits, the string is truncated to retain two digits. if the value is smaller than two digits, the if (f> 2) {endLength = pointRange. location + 2 ;}/// convert tempString to a char array NSUInteger start = 0; const char * tempChar = [tempString UTF8String]; // traversal, remove the for (int I = 0; I <tempString. length; I ++) {if (tempChar [I] = '0') {start ++;} else {break ;}// if the first letter is. returns an if (tempChar [start] = '. ') {start --;} // calculate the length based on the final start position, and intercept the nsange range = {start, endLength-start}; tempString = [tempString substringWithRange: range]; return tempString ;}