-(nsstring*) Getthecorrectnum: (nsstring*) tempstring{//calculate the length of the InterceptNsuinteger endlength =tempstring.length; //determines whether a string is contained. if([tempstring containsstring:@"."]) { //the location of the acquisition.Nsrange Pointrange = [tempstring rangeofstring:@"."]; NSLog (@"%lu", pointrange.location); //judging. There are several behindNsuinteger 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 firstNsuinteger start =0; Const Char*tempchar =[tempstring utf8string]; //Traverse, remove the position that gets the first digit not 0 for(inti =0; i < tempstring.length; i++) { if(Tempchar[i] = ='0') {Start++; }Else { Break; } } //calculates the length according to the final starting position, and interceptsNsrange range = {start,endlength-start}; TempString=[tempstring Substringwithrange:range]; returntempstring;}
iOS string intercept retains two decimal places