IOS float型別比較大小

2021-06-08 09:32:04 字數 1211 閱讀 2493

int bellowgreenlow = 0, bellowgreenhigh = 0, bellowyellowhigh = 0, aboveyellowhigh = 0;

int countsum = 0;

// 兩個floatleixing 比較時,不能直接相減, 當比較是否相等時,應該用兩者之差的絕對值 與精度 相比,如果小於則相等

for (tb_history *temphistory in showhistorys)

if (temphistory.bloodsugar.floatvalue - currentprofile.greenlow.floatvalue > 0.000001 && // 2 比較 大於、小於

currentprofile.greenhigh.floatvalue - temphistory.bloodsugar.floatvalue > 0.000001)

if (abs(temphistory.bloodsugar.floatvalue - currentprofile.greenlow.floatvalue) < 0.000001 || // 2 比較 相等

abs(currentprofile.greenhigh.floatvalue - temphistory.bloodsugar.floatvalue) < 0.000001)

if (temphistory.bloodsugar.floatvalue - currentprofile.greenhigh.floatvalue > 0.000001 && // 3 比較 大於、小於

currentprofile.yellowhigh.floatvalue - temphistory.bloodsugar.floatvalue > 0.000001)

if (temphistory.bloodsugar.floatvalue - currentprofile.greenhigh.floatvalue > 0.000001 && // 3 比較 相等

abs(currentprofile.yellowhigh.floatvalue - temphistory.bloodsugar.floatvalue) < 0.000001)

if (temphistory.bloodsugar.floatvalue - currentprofile.yellowhigh.floatvalue > 0.000001)

}

String 型別比較大小的方式

第一種直接用字串類的compareto方法 1 2 3 string t1 20131011 string t2 20131030 intresult t1.compareto t2 第二種 適用於整數string型別 是把這個日期字串轉換成long 1 2 3 4 dateformat sdf n...

double比較大小

參考 comparing floating point numbers 總結幾點 0.float佔4byte,精度是6 7位 double佔8byte,精度是15 16位。1.因為double型別或float型別都是有精度的,其實都是取的近似值,所以有個誤差。和乙個很小的數比如0.00000001 ...

1235 比較大小

比較大小 time limit 1000ms memory limit 65536k total submit 145 accepted 51 description 輸入兩個十進位制整數a,b,請判斷它們的大小關係。我們重新定義兩個數的大小比較規則為 誰的二進位制表示中含1的個數多誰大,若含1的個...