When the following executes:
NSString *scratchString = @".123456789";
CGFloat scratchNum = [scratchString doubleValue];
scrathNum contains 0.123457
How can I get scratchNum to contain all of the digits? No matter what I try it rounds to 6 places.
When the following executes:
NSString *scratchString = @".123456789";
CGFloat scratchNum = [scratchString doubleValue];
scrathNum contains 0.123457
How can I get scratchNum to contain all of the digits? No matter what I try it rounds to 6 places.
CGFloatは浮動小数点数 -- afloatまたは a double(typedefコンパイラによってどちらが選択されるかによる) です。
「すべての桁を含まない」浮動小数点数の概念はありません。それらの内部表現はさまざまですが、この場合、CはIEEE 754 標準floatによって表されます。
この場合、「丸め」は、その浮動小数点数を取得してバイナリ形式からテキスト形式に変換した結果です。これは、Xcode IDE 自体 (例: デバッガーでの値の視覚化) である場合もあれば、printfステートメントを使用して特定の書式設定を指定している場合もあります。