• 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 very small numbers.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rounding very small numbers.


  • Subject: Rounding very small numbers.
  • From: "Ryan Ragona" <email@hidden>
  • Date: Thu, 11 Sep 2008 01:11:24 -0700

Hey all,

I've been scouring the archives, but coming up without any solution that
seems to work in my application. Here is the issue:

I have some tiny numbers, like -0.000000116916, for example, that I want
rounded to the 5th decimal place or so. -0.00000 is plenty precise for my
purposes.

I attempted to do that with the following code:

NSDecimalNumberHandler* roundingBehavior = [NSDecimalNumberHandler
decimalNumberHandlerWithRoundingMode:NSRoundPlain scale:5];

NSDecimalNumber *roundFloat = [[[[NSDecimalNumber alloc]
                        initWithFloat:0.0000000111123]
                        decimalNumberByRaisingToPower:5]
                        decimalNumberByRoundingAccordingToBehavior:
roundingBehavior];

... but I'm getting the following warning:

"NSDecimalNumberHandler" may not respond to "decimalNumberHandler..."

... and in addition, my code crashes when I attempt to run with this
warning. XCode seems comfortable suggesting the
decimalNumberHandlerWithRoundingMode method, but it does not seem to work.
All of the code examples I see seem to have something exactly like this, but
it isn't at all working with my project.

Do I need to implement a protocol? I'm pretty lost. Am I going about this
totally the wrong way? Is there a much easier way to round? I don't really
need it stored, should I be using C methods? (How do I do that?)

Thanks!

-Ryan
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Rounding very small numbers.
      • From: Keary Suska <email@hidden>
    • Re: Rounding very small numbers.
      • From: Georg Seifert <email@hidden>
  • Prev by Date: Re: OT: Installing Apps
  • Next by Date: Re: OT: Installing Apps
  • Previous by thread: Utility Window needs to hide
  • Next by thread: Re: Rounding very small numbers.
  • Index(es):
    • Date
    • Thread