Rounding off numbers
Rounding off numbers
- Subject: Rounding off numbers
- From: Johan Augustsson <email@hidden>
- Date: Sat, 10 Jun 2006 11:16:50 -0500
Hi!
I have a problem when I round of numbers. My first question is if
there aren't any smother way to round off an NSNumber. I do it like
this:
myNbr is an NSNumber.
NSNumber *myRoundedNbr=[NSNumber numberWithDouble:[[NSString
stringWithFormat:@"%.2f", [myNbr floatValue]] doubleValue]];
The bigger problem is that it doesn't round of correctly. Some tests
show this:
Nbr Rounded
2.265 => 2.27 OK
2.865 => 2.87 OK
2.965 => 2.96 WRONG
What can possibly be wrong and how do I solve it???
I use MacOS X 10.4.6
XCode 2.2
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden