this.promien = Math.sqrt(Math.abs((this.x * this.x) + (this.y * this.y)));
並且x = 0.965(...)y = -15.285(...)。當我試圖解決這個問題時,後面加了這個abs。 this.promien總是0,我不知道爲什麼。我重新啓動Android Studio,沒有幫助。有什麼我看不到的?Android Math.sqrt返回0
public class Pomiary {
public Pomiary() {
}
public Pomiary(double x, double y, double z, Date data, int seria) {
this.x = x;
this.y = y;
this.z = z;
this.data = data;
this.promien = Math.sqrt(Math.abs((this.x * this.x) + (this.y * this.y)));
this.suma = Math.abs(x) + Math.abs(y) + Math.abs(z);
this.seria = seria;
}
@DatabaseField(generatedId = true)
int id;
@DatabaseField(dataType = DataType.DATE_STRING, format = "yyyy/MM/dd HH:mm:ss.SSS")
Date data;
@DatabaseField
double x;
@DatabaseField
double y;
@DatabaseField
double z;
@DatabaseField
double suma;
@DatabaseField
int seria;
@DatabaseField
double promien;
而且我調試這個應用程序,這就是我怎麼知道它是0。同樣要求數據庫返回0,當x和y不等於0。
我在哪裏實例:
if (MainActivity.pomiary) {
double promien = Math.sqrt(Math.pow(X,2) + Math.pow(Y,2));
Pomiary pomiary = null;
try {
pomiary =
new Pomiary(X, Y, Z,
dateFormat.parse(dateFormat.format(new Date())), iloscZapisanychSeriiWBazie);
} catch (ParseException e) {
e.printStackTrace();
}
並且x,y,z是從磁力計值
x和y的定義是什麼? – hotzst
什麼類型是promien – danysz
你怎麼發現結果是0? – laalto