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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:38:26+00:00 2026-06-04T17:38:26+00:00

I have a calculator in which i would like to put the decimal point

  • 0

I have a calculator in which i would like to put the decimal point according to the button press for the decimal point. I get the decimal point but if I enter another digit the decimal pint vanishes and is overwritten .

The code is mentioned below for the decimal press:-

-(IBAction)decimalPressed:(id)sender{
  calculatorScreen.text = [calculatorScreen.text stringByAppendingString:@"."];
}

For the digit press it is :-

-(IBAction)buttonDigitPressed:(id)sender{
  currentNumber = currentNumber*10 + (float)[sender tag];
  calculatorScreen.text = [NSString stringWithFormat:@"%g",currentNumber];
}

How can i do something like 23 then “.” then 45. The result would be 23.45

  • 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-04T17:38:28+00:00Added an answer on June 4, 2026 at 5:38 pm

    I’ve recently done a calculator app and could understand your problem. Another thing you want to take note about the point is that you do not want to have multiple point in your calculation, e.g. 10.345.1123.5. Simply put, you want it to be a legal float number as well.

    With that said, you can use a IBAction (remember to link it to your storyboard or xib file)

    -(IBAction)decimalPressed:(UIButton *)sender
    {
     NSRange range = [self.display.text rangeOfString:@"."];
    if (range.location ==NSNotFound){
    self.display.text = [ self.display.text stringByAppendingString:@"."];
    }
    self.userIsInTheMiddleOfEnteringANumber = YES;
    }
    

    While it might be possible we are doing on the same project, it could also be entirely different (you starting from scratch by yourself) so i will go through some of the codes

    you could replace UIButton with the default id, but it is better to static replace it to make clear clarification for yourself, or anyone else who view your code.

    NSRange as the name implies, mark the range, and the range will be ur display text of calculation (e.g. 1235.3568), and the range of string it is targeting in this case is “.”
    therefore, if NSNotfound (rangeOfString “.” is not found in the text range) you will append the current display text with “.” with the function stringByAppendingString:@”.”, there is no else, so no function will take place if “.” is already found, which solve the problem of multiple point on the display.

    userIsInTheMiddleOfEnteringANumber is a BOOL to solve the problem of having 0 in ur display (e.g. 06357), if you have a method to change it, then replace my method name with your own.

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

Sidebar

Related Questions

I have two fields which calculate a total, but I have a radio button
I have a calculator application in java swing, which is working properly with mouse
I have the following text input on a budget calculator form which displays the
I have read through the similar questions but do not see one like this.
The Back Story I have some decimal values which I am displaying as strings
I have a win form UI that looks like a typical calculator. Naturally I
I have a sticky side menu that I would like to have be able
For a specialized calculator I would like to allow copy / paste for a
So I have a physical chart of time intervals (minute:second) which map to point
Ive got a simple modless dialog which I would like to place at the

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.