Android examples for java.util.regex:Number Pattern
is string a Float number via regular expression
import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Base64; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static boolean isFloat(String str) { if (isLong(str)) { return true; }//from www .jav a 2 s .co m Pattern pattern = Pattern.compile("\\d*\\.{1}\\d+"); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; } return true; } public static boolean isFloat(String str, int precision) { String regStr = "\\d*\\.{1}\\d{" + precision + "}"; Pattern pattern = Pattern.compile(regStr); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; } return true; } }