iOS string intercept retains two decimal places

Source: Internet
Author: User

-(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.