How to check double value is empty or not

I am trying to get double value from json, I want to ask how to check double value, empty or not?

that's how i start it private static

final String kartu_xcord = "xcord";
    private static final String kartu_ycord = "ycord";
    ouble xcord,ycord;

this is how i parse my json:

xcord = c.getDouble(kartu_xcord);
ycord = c.getDouble(kartu_ycord);

this is how i try to check xcord null or empty:

if (xcord.isNaN()) {
            LinlayNoMap.setVisibility(View.VISIBLE);
        } else {
            linlaymap.setVisibility(View.VISIBLE);
}

Hope someone can help me solve my problem, thank you.

+4
source share
7 answers

Do this with Doublenot Doubleand verify that the value Doubleis null, the java value Doublecannot be null.

+11
source

In Java doubleit cannot be null.

+3
source

. . , Double wrapper?

+1

, json , :

if (c.hasDouble("my_coord")) {
  y_coord = c.getDouble("my_coord");
}

y_coord Double ( D), null.

if (c.hasDouble("my_coord")) {
  y_coord = c.getDouble("my_coord");
} else {
  y_coord = null;
}

, , API, , JSON, hasDouble - . GSON, .

+1

Java. hasKey Json, , , , .

c.hasKey("xcord")
0

, JSONObject,

xcord = c.optDouble(kartu_xcord, Double.MIN_VALUE);

if (xcord == Double.MIN_VALUE){
  //xcord is empty
}
0

Double, double.

Double  dValue= someVariable;

if(!dValue.isNaN())
{
 // you code here
}
-one
source

All Articles