I want to validate a string input for a float value.
Is there a way to check if a float value is being truncated (precision is being lost) when parsing a String with a call to Float.parseFloat()?
For example, a user enters too many numbers in an EditText. I want to check when this happens so I can prevent it. I am not trying to get an exact result, I'm just trying to limit the value that a user can enter so it does not exceed the precision limit of a float.
float f = Float.parseFloat("9999999.999"); //this returns 1.0E7 but doesn't throw any error.
I understand that for accuracy I would be using BigDecimal rather a floating-point type. But floating-point accuracy is not my concern here. My concern is validation of the user’s textual input representing a float value.