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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:25:53+00:00 2026-06-02T18:25:53+00:00

Ive scoured everywhere and haven’t found a situation similar to mine.. New to Xcode/Objective

  • 0

Ive scoured everywhere and haven’t found a situation similar to mine.. New to Xcode/Objective C, I am putting together a dual purpose (fraction/decimal) calculator app. Ive found some good stuff on the fractions, and have them calculating correctly. However the decimal is a different story. I can get it to appear with this:

    -(IBAction) pressDecimal
    {
     NSRange range = [display.text rangeOfString:@"."];
                 if ( range.location == NSNotFound ) {
                 display.text = [display.text stringByAppendingString:@"."];
    }

or this:

    -(IBAction) pressDecimal
 {
   [displayString appendString: @"."];
   display.text = displayString;
 }

The latter works great, to DISPLAY it on the calculator. I try to read it in as a slot, a double, and i just can’t seem to read it in properly… here is how i get the digits in:

     - (void) workNums: (int) nums

{

currentNumber = currentNumber * 10 + nums;
[displayString appendString:
 [NSString stringWithFormat: @"%i", nums]];
display.text = displayString;

}

    //uses tags from attribute inspector (decimal tagged 10)
  -(IBAction)pressNum:(UIButton *)sendIT
{
   int nums = sendIT.tag;
   [self workNums: nums];
}

Ive looked everywhere, tried changing from floats to doubles ( i can get it to display 0.00’s when i play with them) also here is my method to converting the ANSWER that is a FRACTION to a DECIMAL..which works great too:

  - (double) convertToNum
 {
if (denominator != 0)
    return (double) numerator / denominator;
else 
    return NAN;

So again, cleanly stated… How may I get Objective C to see the decimal inputed in the app, and display the answer as a decimal properly.. am i screwed because i started this a mainly a fraction calculator? Thanks from a noob that moved from BASIC to Objective C

EDIT 4/27/12 ***
(new to Stack – but please read my comment below.. i am looking to find out why i can’t read decimals into my program… I’ve tried changing from ints (which i know won’t work) and doubles and floats, but all i get is 0.00 on user input when running this all as doubles:

     -(IBAction)pressNum:(UIButton *)sendIT
     {
         int nums = sendIT.tag;
         [self workNums: nums];
     }

        - (void) workNums: (int) nums
     {

     currentNumber = currentNumber * 10 + nums;
     [displayString appendString:
     [NSString stringWithFormat: @"%i", nums]];
     display.text = displayString;
     }

So the goal is to be able to CALCULATE a user inputted decimal number…any suggestions on a if/else situation as these numbers build up in an accumulator / and a double for currentNumber and get turned into numerators/denominators later down the line..(which is probably my issue, but it shouldn’t be hard, but I’m making it hard, to use a BOOL or something to say, hey..this isn’t a fraction, its a decimal – so lets do this – PLEASE HELP!! GOING NUTS!

  • 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-02T18:25:55+00:00Added an answer on June 2, 2026 at 6:25 pm

    I may be thinking this is much simpler than it is, but: if you already have a string like @"3.14" in displayString then you can convert that directly to a double:

    double doubleValue = [displayString doubleValue];
    

    Would that not be enough to get the double value and perform calculations?

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

Sidebar

Related Questions

I've scoured the web for an answer to this and while I've found similar
I've scoured the internet for several hours and turned up similar questions to mine,
I've scoured the interwebs and found many posts regarding how to change the colors
I've scoured the web and found a lot about working with git-svn and branches,
I'm new to MVC3 and have run into a little problem. I've scoured the
New to XML/XSL/Xpath, and I've scoured these boards for an answer to a seemingly
I've scoured the Web looking for examples on how to do this. I've found
I've scoured the web to no avail. Is there a way for Xcode and
I've scoured Google and found to large a variety of tools and answers. I
I've scoured google for an example on scrolling to an element by ID on

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.