To check if a value is a double value in Android you can use the snippet below.

Samples

Java (Android) Sample

public static boolean IsDoubleValue(String input) {
	if(!TextUtils.isEmpty(input.trim())) { //use if(!input.trim().toString().equals("")) { if you are not on the Android platform
		String regExp = "[\\x00-\\x20]*[+-]?(((((\\p{Digit}+)(\\.)?((\\p{Digit}+)?)([eE][+-]?(\\p{Digit}+))?)|(\\.((\\p{Digit}+))([eE][+-]?(\\p{Digit}+))?)|(((0[xX](\\p{XDigit}+)(\\.)?)|(0[xX](\\p{XDigit}+)?(\\.)(\\p{XDigit}+)))[pP][+-]?(\\p{Digit}+)))[fFdD]?))[\\x00-\\x20]*";
		return input.matches(regExp);
	}else{
		return false;
	}
}

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

4 thought on “How to check if a value is a double value in Android (Java)”

Leave a Reply