Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
double M=log(7); M=pow(M_E,M); // M = 7 !!!!!! NSString *B = [[NSNumber numberWithDouble:M] stringValue]; // B=6.999999999 !!!!
但:
double M=7; NSString *B = [[NSNumber numberWithDouble:M] stringValue]; // B=7
为什么这两个例子会产生不同的结果?
浮点值不能精确地表示每个实数,因此您通常会得到非常轻微的这样的结果。例如,(1.0 / 3.0) * 3.0不精确地给出 1。
(1.0 / 3.0) * 3.0