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

  • Home
  • SEARCH
  • 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 9161519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:59:04+00:00 2026-06-17T13:59:04+00:00

My objective is to create a customer calculator application for iPhone and am using

  • 0

My objective is to create a customer calculator application for iPhone and am using Xcode to write my application. My problem that I cannot find a solution for is how to format a number without using scientific notation or a set number of decimals.

I tried…

buttonScreen.text = [NSString stringWithFormat:@"%f",currentNumber];

buttonScreen.text = [NSString stringWithFormat:@"%g",currentNumber];

%f formatting always prints 6 digits after the decimal place so if the user types in “5” it displays 5.000000.

%g formatting jumps to scientific notation after 6 digits so 1000000 becomes 1e+06 when displayed.

I want to be able to have the following numbers display without pointless decimals or scientific notation:

123,456,789;
1.23456789;
12345.6789;
-123,456,789;
-1.23456789;
-12345.6789;
  • 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-17T13:59:05+00:00Added an answer on June 17, 2026 at 1:59 pm

    For floating point number formatting you can use %f, and you have to specify the minimum field width and the precision in terms of characters. If you use %4.2f, means four characters wide minimum (if less than 4 are used, will be filled with blank spaces at left) and 2 characters for precision. If you want 10 characters of minimum wide and 0 of decimal precision, you use %10.0f .

    In your particular case, you should use %.0f for no digits of decimal precision.

    buttonScreen.text = [NSString stringWithFormat:@"%.0f",currentNumber];
    

    You can find a quick reference here . Is not the objective-c documentation, but is equivalent.

    For the sake of completeness, you can find the documentation of the specification that NSString formatting follows in:

    https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html

    and here:

    http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html

    EDIT for truncation:

    buttonScreen.text = [NSString stringWithFormat:@"%d",(int)currentNumber];
    

    But, you should read a little about floating representation, precision and casting to be aware of possible undesired behavior.

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

Sidebar

Related Questions

My objective is to create a customer calculator application for iPhone and I am
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I want to create an objective c application that interprets a list of .aiml
My end objective is to create an applescript that intelligently inserts a bullet point
I need to create an Objective-C method that converts an int into a byte
I'm trying to create an objective C classe for my iPad application which can
Objective: I want to create a web service that allows me to connect to
How to create a TCP socket using Objective-C, check if some TCP ports are
My objective is create an apache module that will provide RESTful services (i.e., we
The objective is to create a custom route so that /undead will go to

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.