To find the maximum and minimum value of Float , we would be invoking two if it’s fields. Maximum value of an Float object is 3.4028235E38 which can be found using
and the minimum value of Float is 1.4E-45 which can be found also using one of the fields of Float
So why do we care about these values? First reason is to know the limit on what value should we assign to our Float object. Secondly if we go through on the methods of the Float class we would find some parsing and conversion from another object type to Float type. Lets try to take a look on the parsefloat(String s) method which take an argument string and convert it into Float object. So what if we pass a string value which has a float equivalent that is higher than the maximum value as defined by the Float.MAX_VALUE? To have a birds eye view of this scenario lets take a look on below example:
Float testValue = Float.parseFloat("3.4128235E38");
As you would have noticed we have passed a method argument to parseint method that is greater than maximum value which certainly breached the threshold. So if we try to run the above code snippet, the value printed will be Infinity .