I'm trying to check for no input from the user and if there's no input just make it zero.
When there's no input or the input is invalid, valueOf
does not return a NaN
; it throws NumberFormatException
. You can add a try
/catch
around the valueOf
call (since you want float
, not Float
, you should use parseFloat
instead to avoid the unnecessary boxing and unboxing of the value):
float aa;
try {
aa = Float.parseFloat(a.getText().toString());
} catch (NumberFormatException nfe) {
aa = 0;
}