What's the difference between the 2 codes below?
1st
int x = 10;
float i = (float) x;
2nd
int x = 10;
float i = Float.parseFloat(x);
What's the difference between the 2 codes below?
1st
int x = 10;
float i = (float) x;
2nd
int x = 10;
float i = Float.parseFloat(x);
It's very simple, the first works, and the second does not, it does not make sense to do a parsing in an integer, just in strings . Then the documentation shows that you can only pass one string .
Alias the method name is a "primor": P
The first one indicates that a number that was integer should be interpreted as a binary floating-point type. There will be a conversion because the formatted of each type is different. It actually works without this, there is an implicit conversion from int
to float
as language specification .