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 8458487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:05:39+00:00 2026-06-10T13:05:39+00:00

I am a beginner Objective-C programmer and I was building a calculator as my

  • 0

I am a beginner Objective-C programmer and I was building a calculator as my first app. I am using an NSNumberFormatter to format the Calculator’s display. It converts NSNumber to NSString correctly, but doesn’t parse NSString to NSNumber right if they have a comma separator. Here’s the code:

- (IBAction)digitPressed:(NSButton *)sender {
    if (userIsEnteringANumber) {
        NSNumber *number = [formatter numberFromString:[self.calDisplay.stringValue stringByAppendingString:sender.title]];
        self.calDisplay.stringValue = [formatter stringFromNumber:number];
    }
    else {
        self.calDisplay.stringValue = sender.title;
        userIsEnteringANumber = YES;
    }
}

If calDisplay.stringValue = @“2,569”, then pressing another digit sets number to nil.

  • 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-06-10T13:05:41+00:00Added an answer on June 10, 2026 at 1:05 pm

    Pragmatically I would simply remove the comma before parsing the string into a number then it must work.

     NSString *s = [self.calDisplay.stringValue 
                    stringByReplacingOccurrencesOfString:@"," withString:@""];
    

    Leaving you with

    - (IBAction)digitPressed:(NSButton *)sender {
       if (userIsEnteringANumber) {
           NSString *s = [self.calDisplay.stringValue stringByReplacingOccurrencesOfString:@"," withString:@""];
           NSNumber *number = [formatter numberFromString:[s stringByAppendingString:sender.title]];
           self.calDisplay.stringValue = [formatter stringFromNumber:number];
       } else {
           self.calDisplay.stringValue = sender.title;
           userIsEnteringANumber = YES;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a total beginner to Objective C. Currently I try to display a
hello i am a beginner in objective-c i have a nsstring like this Select
Greetings! as a beginner in iPhone application development using Objective-C, I was wondering what
Im a beginner so please bear with me... In my app using xcode and
i've been doing a thing here using objective-c, but i'm a beginner in this
i've been doing a thing here using objective-c, but i'm a beginner in this
I am a beginner ObjectiveC programmer, coming from the C++ world. I find it
I'm a beginner with Objective C and iPhone development. It's there any way to
I'm a beginner at Objective-C and am trying to initialize an NSMutableArray with objects
I'm a Objective-C beginner and now I want to loop trough an array and

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.