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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:10:22+00:00 2026-06-03T03:10:22+00:00

I am trying to add a positive/negative button onto a numerical input in a

  • 0

I am trying to add a positive/negative button onto a numerical input in a UItextfield, but I cannot get it to function properly. What I want it to do is just add or remove a negative sign from the front of the numerical input. I am able to do that, however I cannot find a method to maintain the original number of decimal places. This is what I have tried:

- (IBAction) negsign
{
    float input = [userinput.text floatValue];
    float result = ((input * (-1)));
    negstring = [NSString stringWithFormat:
                          @"%f", result];
    userinput.text = negstring;
}

With this I get just a string of zeros after, like -23.0000000. I’ve tried limiting the decimal places by changing to @”%.2f” but I dont want extra zeros for whole integers, or rounding more than 2 decimals places. I just want it to take something like 34.658939 or 23 and make it -34.658939 or -23. Does anyone have a method to do this?

  • 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-03T03:10:23+00:00Added an answer on June 3, 2026 at 3:10 am

    What would work best in your case is the following code:

    float input = [userinput.text floatValue];
    float result = ((input * (-1)));
    NSNumber *resultNum = [NSNumber numberWithFloat:result];
    NSString *resultString = [resultObj stringValue];
    userinput.text = resultString;
    

    If you’re trying to make the number negative instead of reversing the sign, it’d be better if you replace float result = ((input * (-1))); with float result = -ABS(input);

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

Sidebar

Related Questions

Trying to add a new element to the DOM but I get all sorts
I'm trying to write a function that allows me to add only the positive
Trying to add an onclick handler to my tabs, and can't seem to get
Trying to add a class object into a List using reflection, but when invoking
I'm trying to create an Aler Dialog but when I click on button my
I'm trying to get more familiar with HTML5. I am an experienced programmer, but
I'm trying to create simple Ajax call, but after clicking the link I get
I'm trying to make a proof of concept website, but I want perfect degradation.
I'm trying add vertical lines to my grid. I have found some examples but
I'm trying add a tab to my web page that looks like this: Using

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.