Convert jdouble to double of type c

How to convert jdoublejava doubletype variable into c variable ?

+5
source share
2 answers

You don't need this, it's just a typedef, for example:

typedef double jdouble;

Thus, no conversion is required, as soon as you have it jdouble, you can treat it the same way double.

See for example an example from Standford :

JNIEXPORT jdouble JNICALL Java_Summer_sum__DD
(JNIEnv *env, jobject jobj, jdouble j1, jdouble j2) {
    return j1 + j2;
}

Adding is done directly with the values jdouble, trusting the compiler to figure out how to generate the required code.

+5
source

No conversion is required. I used a simple static composition.

jfieldID varPtr = env->GetFieldID(dataClass, "var", "D");
jdouble jdoubleVar = env->GetDoubleField(dataClass, varPtr);

double varDouble = static_cast<double>(jdoubleVar);
0
source

All Articles