• 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
Re: rounding a float
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rounding a float


  • Subject: Re: rounding a float
  • From: "Jay Rimalrick" <email@hidden>
  • Date: Sun, 30 Nov 2003 12:56:56 -0500

I am attempting write a function that take a float (inFloat) and returns a float
(hopefully rounded for currency)

Here is what I do inside my function:

NSString* myString = [[NSString alloc] init];
myString = [NSString stringWithFormat: @"%f", inFloat];


NSDecimalNumber* myDecimalNumber = [[NSDecimalNumber alloc] init];
myDecimalNumber = [NSDecimalNumber decimalNumberWithString:
myString];

NSDecimalNumber* roundedDecimalNumber = [[NSDecimalNumber alloc]
init];

NSDecimalRound((NSDecimal*)roundedDecimalNumber,
(NSDecimal*)myDecimalNumber, 2, NSRoundPlain);

NSLog(@"%f", [roundedDecimalNumber doubleValue]);

return [roundedDecimalNumber doubleValue]; //i tried float value too

-when I use [roundedDecimalNumber doubleValue] I get the error "myProgram
has exited due to signal 11 (SIGSEGV)" in the debugger it tell me "GDB:
Program received signal: "EXC_BAD_ACCESS""

for some reason it is not passing back the roundedDecimalNumber

any and all help is greatly appreciated




________________________________________________________________
Sent via the WebMail system at 1st.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: rounding a float
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: Dynamic UI
  • Next by Date: problem with custom NSFormatter and NSTextField
  • Previous by thread: Re: rounding a float
  • Next by thread: Re: rounding a float
  • Index(es):
    • Date
    • Thread