Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:04:51+00:00 2026-05-16T11:04:51+00:00

HI, Due to formatting issues, I’m converting floats to NSNumber in my iPhone app.

  • 0

HI,

Due to formatting issues, I’m converting floats to NSNumber in my iPhone app. Although it generates proper strings it crashes program after releasing the object.

I wrote simple program as console app for Mac OS X and same problem occurs. Can anybody advise how to solve that? Here is the code sample. All 3 messages are written to log and after that EXEC_BAD_ACCESS error occurs…

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSString *FormattedValueString = [[NSString alloc] init];
    NSString *FormattedValueString1 = [[NSString alloc] init];



    NSNumber *myNumber = [[NSNumber alloc] initWithDouble:100.345];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 
    [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; 

    FormattedValueString = [myNumber stringValue];
    FormattedValueString1 = [numberFormatter stringFromNumber:myNumber];

    NSLog(FormattedValueString);
    NSLog(FormattedValueString1);

    [FormattedValueString release];
    [FormattedValueString1 release];
    [numberFormatter release];
    [myNumber release];

    NSLog(@"Everything OK");

    [pool drain];
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:04:52+00:00Added an answer on May 16, 2026 at 11:04 am

    FormattedValueString and FormattedValueString1 are both autoreleased and so do not need to be released manually. And you don’t need to alloc/init the values at the start of the function; the assignment further down overwrites these values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how
I have had to change a UIScrollView into a UIWebView due to formatting reasons.
I am using Appcelerator Titanium for an Android app and the code below generates
I am trying to convert DateTime object to string using formatting but due to
Due to a sad situation I receive HTML like this: <p>Perform the following commands:
Due to legacy reasons a lot of our data is stored encoded in standard
Due to an incident a few months prior, thousands of author_ids have been deleted
Due to a bug in my javascript click handling, multiple Location objects are posted
Due to some css limitations between IE and the rest of the world I
Due to a number of constraints that I won't get into, I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.