FROM : Johan Augustsson
DATE : Sat Jun 10 18:16:50 2006
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
DATE : Sat Jun 10 18:16:50 2006
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
| Related mails | Author | Date |
|---|---|---|
| Johan Augustsson | Jun 10, 18:16 | |
| John Stiles | Jun 10, 18:46 | |
| James Bucanek | Jun 10, 18:56 |






Cocoa mail archive

