Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Java, how do you check if a float variable is null?

It seems that when it comes to *value.getFloat("Value_Quotient", quotient_Float)==null*, it encounters a problem. How do I fix this?

private void Store() {
    quotient_Float = posture_error/time;
    if(value.getFloat("Value_Quotient", quotient_Float)==null || quotient_Float < value.getFloat("Value_Quotient", quotient_Float))
    {
        editor.putFloat("Value_Quotient", quotient_Float);
        editor.commit();
    }           
}
like image 427
Christopher Treanor Avatar asked Aug 28 '13 15:08

Christopher Treanor


People also ask

How to check if an object is null in Java?

null check is used for objects. For primitives you should use the default values check. For float the default value is 0.0f. There is also a Float class that you can use. The Float object can be checked for null as its an object representation of a float data type.

How to check if a float is null or not?

There is also a Float class that you can use. The Float object can be checked for null as its an object representation of a float data type. A Float object is represented by a capitol F, and the float data type has a small f.

What is the default value of float in Java?

float is a primitive data type and not an object. null check is used for objects. For primitives you should use the default values check. For float the default value is 0.0f.

How to check if a variable is null in C++?

You can use a basic ‘if’ statement to check a null in a piece of code. Null is commonly used to denote or verify the non-existence of something. Within that context, it can be used as a condition to start or stop other processes within the code. [1] Use "=" to define a variable. A single "=" is used to declare a variable and assign a value to it.


1 Answers

float is a primitive data type and not an object. null check is used for objects. For primitives you should use the default values check. For float the default value is 0.0f.

like image 160
Juned Ahsan Avatar answered Oct 05 '22 22:10

Juned Ahsan