JAVA -> GWT -> JS 双值比较

JAVA -> GWT -> JS double value comparison

我在比较两个 double 时遇到了一些麻烦。

如果我使用这些值,我会有一个奇怪的行为(如果 a > b a 比较给出 b < a !!)。

'report' 是由 GWT rpc

创建的 class
double A = report.getR_press_delta_pressure();
double B = report.getR_press_0_delta();

Window.alert("compare("+A+", "+B+") = "+Double.compare(A, B));

compare(50.0,200.0) = 1

A = 50.0;
B = 200.0;
Window.alert("compare("+A+", "+B+") = "+Double.compare(A, B));

compare(50.0,200.0) = -1 (OK)

A = Double.parseDouble(""+report.getR_press_delta_pressure());
B = Double.parseDouble(""+report.getR_press_0_delta());
Window.alert("compare("+A+", "+B+") = "+Double.compare(A, B));

compare(50.0,200.0) = -1 (OK)

我用 classic comparison ">", "<"

得到同样的错误

这是有原因的吗? 难道我做错了什么?

自动生成get()方法:

public final native double getR_press_delta_pressure() /*-{
    return this.r_press_delta_pressure;
}-*/;

public final native double getR_press_0_delta() /*-{
    return this.r_press_0_delta;
}-*/;

代码被GWT从Java置换为HTML + JS,所以最终的函数是JS

我想我已经解决了: 在 php 文件中,我从 sqlite 数据库中检索值,这里我需要指定该值是一个浮点数,如下所示:

$result->r_press_0_delta = floatval($row['r_press_0_delta']);
$result->press_delta_pressure = floatval($row['press_delta_pressure']);

谢谢大家