0
我正在嘗試實現下面的代碼片段。但是我無法得到我的預期結果。例如,如果我的disanceFromLoc = 0.16,我仍然將我的輸出值設爲0.16公里。Objective C:數字之間的比較問題
我比較價值的方式有什麼問題嗎?對象是'NSNumber'類(在覈心數據中將其定義爲雙精度)
if ([object.distanceFromLoc doubleValue] < 0)
{
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"Approx. Distance: %0.2f m", [object.distanceFromLoc doubleValue]*1000];
}
else
{
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"Approx. Distance: %0.2f km", [object.distanceFromLoc doubleValue]];
}
謝謝!
Zhen Hoe
謝謝,多麼愚蠢的錯誤。謝謝! – Zhen 2011-05-16 07:33:05