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