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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:45:14+00:00 2026-06-09T16:45:14+00:00

So I’ve coded a calculator in objective C and I’ve formatted the display in

  • 0

So I’ve coded a calculator in objective C and I’ve formatted the display in .4g as I wanted only significant digits and 4 decimal places. This works fine 🙂
What I would like it to do is not display 2.34E+05 etc when it displays a longer number like 234,000. I’ve allowed it to autosize the text in the label so I know it isn’t just that the label is too small.
Is there a piece of code that will make it display the actual number instead of the scientific notation?

  • 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-09T16:45:15+00:00Added an answer on June 9, 2026 at 4:45 pm

    Formatting with %f instead of %g won’t use standard form.

    Have a look at this specification.


    Edit 1:

    I found this answer to help with the rounding.

    -(float) round:(float)num toSignificantFigures:(int)n {
        if(num == 0) {
            return 0;
        }
    
        double d = ceil(log10(num < 0 ? -num: num));
        int power = n - (int) d;
    
        double magnitude = pow(10, power);
        long shifted = round(num*magnitude);
        return shifted/magnitude;
    }
    

    I then combined these two options to get:

    NSLog(@"%.0f", [self round:number toSignificantFigures:4]); 
    

    Edit 2:

    What about this:

    - (NSString *) floatToString:(float) val {
        NSString *ret = [NSString stringWithFormat:@"%.5f", val];
        unichar c = [ret characterAtIndex:[ret length] - 1];
        while (c == 48 || c == 46) { // 0 or .
            ret = [ret substringToIndex:[ret length] - 1];
            c = [ret characterAtIndex:[ret length] - 1];
        }
        return ret;
    }
    

    I haven’t tested this, but it looks as if it limits decimals to 5, then removes any trailing zeros or decimal points.

    [Source]

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.