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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:37:15+00:00 2026-06-03T00:37:15+00:00

Hi all I am using below method to get string from NSNumber -(NSString *)stringFromNumber:(NSNumber

  • 0

Hi all I am using below method to get string from NSNumber

     -(NSString *)stringFromNumber:(NSNumber *)number
    {
        NSLog(@"Input:---%@",number);
        NSNumberFormatter *numFormatter = [[[NSNumberFormatter alloc] init] autorelease];
        [numFormatter setMaximumFractionDigits:5];
        [numFormatter setMinimumFractionDigits:2];
        //[numFormatter setExponentSymbol:@"e"];
        NSString *str_num = [numFormatter stringFromNumber:number];
        NSLog(@"Output:---%@",str_num);
        return str_num;
    }

in console i am getting like below

    Input:---2.940000057220459
    Output:---2.94                
    Input:---2940.000057220459
    Output:---2940.00006         
    Input:---2.940000057220459e-15
    Output:---.00                 
    Input:---2.940000057220459e-12
    Output:---.00                 
    Input:---2.940000057220459e-09
    Output:---.00                 
    Input:---2.940000057220459e-06
    Output:---.00                 
    Input:---0.002940000057220459
    Output:---.00294             

but I need the output to look like below for above inputs (order)

---2.94
---2940
---2.94e-15
---2.94e-12
---2.94e-6
---2.94e-9
---0.00294

How would I do it? Someone please help me.

  • 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-03T00:37:17+00:00Added an answer on June 3, 2026 at 12:37 am

    i tried this

    -(NSString *)stringFromNumber:(NSNumber *)number
    {
        NSLog(@"Input:---%@",number);
        NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
        [numFormatter setMaximumFractionDigits:5];
        [numFormatter setMinimumFractionDigits:2];
        NSString *temp = [NSString stringWithFormat:@"%@",number];
        NSRange range = [temp rangeOfString:@"e"];
        if(range.length > 0){
            [numFormatter setNumberStyle:NSNumberFormatterScientificStyle];
            [numFormatter setExponentSymbol:@"e"];
        }
        NSString *str_num = [numFormatter stringFromNumber:number];
        NSLog(@"Output:---%@",str_num);
        return str_num;
    }
    

    and Got like this

    Input:---2.940000057220459
    Output:---2.94
    Input:---2940.000057220459
    Output:---2940.00006
    Input:---2.940000057220459e-15
    Output:---2.94e-15
    Input:---2.940000057220459e-12
    Output:---2.94e-12
    Input:---2.940000057220459e-09
    Output:---2.94e-9
    Input:---2.940000057220459e-06
    Output:---2.94e-6
    Input:---0.002940000057220459
    Output:---.00294
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using all of the below to take a field called 'code' from my
I hope to list all files in document directory using codes below for(NSString *path
First of all, i'm using the function below to read data from a pdf
I can get the list of country names using below code, (copied from somewhere
I am using the below code in my test class , to load all
Afternoon all, Using the code below I'm trying to load what is render by
I'm using Sql-Server, and I have the below query which returns all columns that
I need a way to remove ALL using statements from code and fully qualify
We have a large number of programmers on different platforms all using CVS. We
Here i am trying to get uContainer object from another project. uContainer having all

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.