我在比较两个双精度时遇到了一些麻烦。
如果我使用这些值,我会有一个奇怪的行为(如果 a> b 比较给出 b
"报告"是由 GWT rpc 创建的类
double A = report.getR_press_delta_pressure();
double B = report.getR_press_0_delta();
Window.alert("compare("+A+", "+B+") = "+Double.compare(A, B));
比较 (50.0,200.0( = 1
A = 50.0;
B = 200.0;
Window.alert("compare("+A+", "+B+") = "+Double.compare(A, B));
比较(50.0,200.0( = -1 (正常(
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));
比较(50.0,200.0( = -1 (正常(
我在经典比较">"、"<"中获得相同的错误
这是有原因的吗?我做错了什么吗?
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 db 中检索值,这里我需要指定该值是浮点数,如下所示:
$result->r_press_0_delta = floatval($row['r_press_0_delta']);
$result->press_delta_pressure = floatval($row['press_delta_pressure']);
谢谢大家。