"Code note" floating-point number processing and removing the extra 0

Source: Internet
Author: User

One, code.

-(void) viewdidload{    [Super Viewdidload];    Do any additional setup after loading the view.        NSLog (@ "--float-%@-", [self stringdisposewithfloat:9.000899990000]);    } #pragma-mark-functions//floating-point number to process and remove excess 0-(NSString *) Stringdisposewithfloat: (float) floatvalue{nsstring    *str = [ NSString stringwithformat:@ "%f", Floatvalue];    Long len = str.length;    for (int i = 0; i < len; i++)    {        if (![ Str  hassuffix:@ "0"]) break            ;        else            str = [str substringtoindex:[str length]-1];    }    if ([Str hassuffix:@ "."]) Avoid being parsed into 2 like 2.0000.    {        //s.substring (0, len-i-1);        return [str substringtoindex:[str length]-1];    }    else    {        return str;}    }

Two, output.

2015-10-16 09:53:45.765 floating point processing and removing redundant 0[1554:47555]--float-9.0009-2015-10-16 09:53:48.824 floating point number processing and removing redundant 0[1554:47619] Terminating since there is no system app.

"Code note" floating-point number processing and removing the extra 0

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.