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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:29:51+00:00 2026-05-25T19:29:51+00:00

So, look at the following code below- my first question is, how can I

  • 0

So, look at the following code below- my first question is, how can I make it so there is only 0, 1, or 2 decimal places or make it automatically have however many decimal places are there? the second question is, how would I add a decimal button to the calculator? it has +-/*, how would I add a decimal button? Tutorial I used is here http://www.youtube.com/watch?v=Ihw0cfNOrr4 and here is my code-

viewcontroller.h

 #import <UIKit/UIKit.h>

@interface calcViewController : UIViewController {

float result;
IBOutlet UILabel *calculatorScreen;
int currentOperation;
float currentNumber;

}


-(IBAction)buttonDigitPressed:(id)sender;
-(IBAction)buttonOperationPressed:(id)sender;
-(IBAction)cancelInput;
-(IBAction)cancelOperation;



@end

in the .m

 #import "calcViewController.h"

@implementation calcViewController



-(IBAction)buttonDigitPressed:(id)sender {


currentNumber = currentNumber *10 + (float)[sender tag];
calculatorScreen.text = [NSString stringWithFormat:@"%2f", currentNumber];

}

-(IBAction)buttonOperationPressed:(id)sender {
if (currentOperation ==0) result = currentNumber;
else {


    switch (currentOperation) {
        case 1:
            result = result + currentNumber;
            break;
        case 2:
            result = result - currentNumber;
            break;
        case 3:
            result = result * currentNumber;
            break;
        case 4:
            result = result / currentNumber;
            break;
        case 5:
           currentOperation = 0;
            break;




    }
}
currentNumber = 0;
calculatorScreen.text = [NSString stringWithFormat:@"%2f", result];
if ([sender tag] ==0) result=0;
currentOperation = [sender tag];

}

-(IBAction)cancelInput {

currentNumber =0;
calculatorScreen.text = @"0";

}


-(IBAction)cancelOperation {



currentNumber = 0;
calculatorScreen.text = @"0";
currentOperation = 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-25T19:29:51+00:00Added an answer on May 25, 2026 at 7:29 pm

    you can use this on the output.

    Float *number = 2.2f;
    NSLog(@"%.2f",number);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a look at the following code you are not required to read the
am new here. i have a slight problem; PLease look at the following code
Have a look here: In the following code, what would be the type of
I have the following code to encrypt a value (listed below). Now I would
Have a look at the following code: class A(object): defaults = {'a': 1} def
please have a look at the following code: (I removed all doctypes etc for
Take a look that the following code snippet: A a = null try {
I want to statically allocate the array. Look at the following code, this code
Getting the above error in following code. How to rectify it. Thanks. Please look
If we look at the latest jQuery source at http://code.jquery.com/jquery-latest.js we see the following:

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.