I've defined a method with one parameter of type float shown below:
public float getValue(float value){
return value;
}
When I call this method by passing float value say 10.1201 shown below:
float value = methodReturnTest.getValue(10.1201);
My IDE says to cast the argument to float. I tried searching but couldn't get the appropriate answer. so posting it. Please explain .
Thanks.
Java takes 10.1201
as double
. In order to pass a float
value you should append f
to it like this:
float value = methodReturnTest.getValue(10.1201f);
In java Float Literals are specify by using f at the end otherwise it be treated as double literal.
Do like this
float value = methodReturnTest.getValue(10.1201f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With