• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Rounding off numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Rounding off numbers
      • From: James Bucanek <email@hidden>
    • Re: Rounding off numbers
      • From: John Stiles <email@hidden>
  • Prev by Date: Re: Cocoa newb - Bus Error from TCP Server
  • Next by Date: Re: Rounding off numbers
  • Previous by thread: Re: Cocoa newb - Bus Error from TCP Server
  • Next by thread: Re: Rounding off numbers
  • Index(es):
    • Date
    • Thread