Java regular minus 0 after the decimal point

Source: Internet
Author: User

Requirements: The known string is a numeric character form, many for float,double conversion over, will be after the extra 0 and.

Package test; /** * Remove excess. with 0 * @author Hust * @Time 2011-11-7*/   Public classteststring { Public Static voidMain (string[] args) {Float F=1f; System. out. println (F.tostring ());//1.0System. out. println (Subzeroanddot ("1"));;//1 after conversionSystem. out. println (Subzeroanddot ("Ten"));;//after the conversion is tenSystem. out. println (Subzeroanddot ("1.0"));;//1 after conversionSystem. out. println (Subzeroanddot ("1.010"));;//after conversion to 1.01System. out. println (Subzeroanddot ("1.01"));;//after conversion to 1.01    }            /** * Use Java Regular expressions to remove superfluous. with 0 * @param s * @return*/       Public Staticstring Subzeroanddot (string s) {if(S.indexof (".") >0) {s= S.replaceall ("0+?$","");//Remove the extra 0s = S.replaceall ("[.] $","");//if the last one is. Then remove        }          returns; }        }  

Java regular minus 0 after the decimal point

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.