将float从JNI发送到Java代码会增加2个数字

将float从JNI发送到Java代码会增加2个数字,java,android,c++,android-ndk,java-native-interface,Java,Android,C++,Android Ndk,Java Native Interface,在我的JNI中,我从OpenCL类(java)调用一个函数。我传递一个浮点作为参数,但当我打印它时,它会添加2个diggit JNI发送代码: float ndrangeDuration = (end.tv_sec + end.tv_usec * 1e-6) - (start.tv_sec + start.tv_usec * 1e-6); LOGD("NDRangeKernel time: %f", ndrangeDuration); jclass MyJavaClass = (*e

在我的JNI中,我从OpenCL类(java)调用一个函数。我传递一个浮点作为参数,但当我打印它时,它会添加2个diggit

JNI发送代码:

float ndrangeDuration =
    (end.tv_sec + end.tv_usec * 1e-6) - (start.tv_sec + start.tv_usec * 1e-6);

LOGD("NDRangeKernel time: %f", ndrangeDuration);

jclass MyJavaClass = (*env).FindClass("com/denayer/ovsr/OpenCL");
if (!MyJavaClass){
    LOGD("Aj :(");
    return;} /* method not found */
jmethodID setTimeFromJNI = (*env).GetMethodID(MyJavaClass, "setTimeFromJNI", "(F)V");
(*env).CallVoidMethod(thisObject, setTimeFromJNI, ndrangeDuration);
日志是:

#define  LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
java代码:

public void setTimeFromJNI(float time)
{
    Log.i("setTimeFromJNI","Time set on " + String.valueOf(time));

}
输出:

NDRangeKernel时间:0.104581这是来自JNI的

时间设置为0.10458103这是来自Java

有人能告诉我我做错了什么或看不见什么吗


提前谢谢

值相同,只是打印方式不同

printf(3)
手册页:

   f, F   The double argument is rounded and converted to decimal notation
          in the style [-]ddd.ddd, where the number of  digits  after  the
          decimal-point character is equal to the precision specification.
          If the precision is missing, it is taken as 6; if the  precision
          is  explicitly  zero,  no decimal-point character appears.  If a
          decimal point appears, at least one digit appears before it.
您将注意到,当从JNI打印时,该值在小数点后有6位数字。如果您使用“%.8f”而不是“%f”,则会在两侧看到相同的数字串

您可以在Android中看到Java语言浮点格式代码。注意输出长度没有固定的上限

如果您的目标是获得匹配的输出,那么可以使用打印用Java编程语言编写的代码中的值。对其接受的内容的完整描述在中;如果你深入挖掘,你会发现:

结果中m或a的小数部分的位数等于精度。如果未指定精度,则默认值为6

与本机
printf()
行为匹配