I have been trying the following code in Java :
import java.math.*;
public class trial {
public static void main(String[] args) {
// create a BigDecimal object
BigDecimal bg;
// create a Float object
Float f;
float f2 = 35912062;
bg = new BigDecimal(35912062);
// assign the converted value of bg to f
f = bg.floatValue();
String str = "Float value of " + bg + " is " + f;
bg = new BigDecimal(f);
String str2 = "BigDecimal value of " + bg;
// print f value
System.out.println( str );
System.out.println( str2 );
System.out.println( 35912062f );
System.out.println(f2);
}
}
So, the following is the output I am getting :
Float value of 35912062 is 3.5912064E7
BigDecimal value of 35912064
3.5912064E7
3.5912064E7
Now, I believe that it is because this is extending the range of float but when I read this : What is the inclusive range of float and double in Java?
it shows the inclusive range of float to be : 3.40282346638528860e+38
This has made me really confused. Any links giving explanations will help.
EDIT: Say I take 25912062 inplace of 35912062, The output for 25912062 is 25912062, but for, 35912062 the output is 35912064 why is this so ?