This is probably a super dumb question, but I'm completely new to Objective-C and XCode and the most complicated programming I've ever done was using AS3.
Anyway, I was following along with Cocoa Lab's "Become An XCoder" eBook and was working with Chapter 4: Printing On Screen and decided to plug in this bit of code into XCode 3.6 to test it out:
It worked fine, of course so I decided to play around a bit and see what it did if I added characters to x to make it greater than 10 characters and ran the program. It came up truncated, but rounded it oddly.
For example, I put in: 1234567.5678 and got something like: 1234567.62
There must be a reason why it's rounding .5678 to .62, but I couldn't understand it. When I changed the numbers, I also got some odd rounding. This is probably something to do with how Objective-C works and I'll likely figure it out as I continue to learn more. But it's a curiosity that's bugged me since I can't figure it out and would love an explanation. Keeping in mind that I'm a total newbie. Thanks!
Anyway, I was following along with Cocoa Lab's "Become An XCoder" eBook and was working with Chapter 4: Printing On Screen and decided to plug in this bit of code into XCode 3.6 to test it out:
//[9]
float x=1234.5678;
NSLog(@"Reserve a space of 10, and show 2 significant digits.");
NSLog(@"%10.2f", x);
It worked fine, of course so I decided to play around a bit and see what it did if I added characters to x to make it greater than 10 characters and ran the program. It came up truncated, but rounded it oddly.
For example, I put in: 1234567.5678 and got something like: 1234567.62
There must be a reason why it's rounding .5678 to .62, but I couldn't understand it. When I changed the numbers, I also got some odd rounding. This is probably something to do with how Objective-C works and I'll likely figure it out as I continue to learn more. But it's a curiosity that's bugged me since I can't figure it out and would love an explanation. Keeping in mind that I'm a total newbie. Thanks!