Java Why does the method argument treat the float value as a double value?

I defined a method with one parameter of type float, shown below:

public float getValue(float value){

    return value;
}

When I call this method, passing the float value, say 10.1201 , as shown below:

float value =  methodReturnTest.getValue(10.1201);

My IDE says to have the argument cast to a float. I tried to search, but could not get the corresponding answer. so send it. Please explain.

Thanks.

+4
source share
4 answers

Java accepts 10.1201as double. To pass a value float, you must add fto it as follows:

float value =  methodReturnTest.getValue(10.1201f);
+11
source

java Float Literals f , .

float value =  methodReturnTest.getValue(10.1201f);
+4

Float - 32- 32- IEEE 754 Double - 64- IEEE 754. , 0,23f ( , float), java double.

, java.

+3

f . , Java , float double.

float value =  methodReturnTest.getValue(10.1201f);
+2
source

Source: https://habr.com/ru/post/1524638/


All Articles