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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:36:03+00:00 2026-05-24T16:36:03+00:00

May i know how to round up a NSNumber in object C ? for(int

  • 0

May i know how to round up a NSNumber in object C ?

for(int i=6; i>=0; i--) 
{
    DayOfDrinks *drinksOnDay = [appDelegate.drinksOnDayArray objectAtIndex:i];

    NSString * dayString= [NSDate stringForDisplayFromDateForChart:drinksOnDay.dateConsumed];

    [dayArray addObject:dayString];//X label for graph the day of drink.

    drinksOnDay.isDetailViewHydrated = NO;

    [drinksOnDay hydrateDetailViewData];

    NSNumber *sdNumber =  drinksOnDay.standardDrinks;
    [sdArray addObject: sdNumber];      
}

inside this sdArray are all the numbers like this 2.1, 1.3, 4.7, 3.1, 4.8, 15.1, 7.2;

i need to plot a graph Y axis so i need a string of whatever is from the NSNumber to show
a NSString of this {@”0″, @”2″, @”4″, @”6″, @”8″, @”10″, @”12″,@”14″,@”16″}. as i need to start from zero, i need to determine which is the biggest number value. in this case it will be 15.1 to show 16 in the graph. instead of doing a static labeling, i will like to do a dynamic labeling.

enter image description here
what you have seen in the graph is static numbering not dynamic.

i’m sorry for missing out the important info.

thanks for all the comments

  • 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-05-24T16:36:04+00:00Added an answer on May 24, 2026 at 4:36 pm

    Your edit now makes a lot more sense. Here is an example of getting all even numbers from your 0 to your max value in your NSArray of NSNumbers (assuming all values are positive, could be changed to support negative values by finding minimum float value as well).

    NSArray *sdArray = [NSArray arrayWithObjects:
                        [NSNumber numberWithFloat:2.1],
                        [NSNumber numberWithFloat:1.3],
                        [NSNumber numberWithFloat:4.7],
                        [NSNumber numberWithFloat:3.1],
                        [NSNumber numberWithFloat:4.8],
                        [NSNumber numberWithFloat:15.1],
                        [NSNumber numberWithFloat:7.2],
                        nil];
    
    //Get max value using KVC
    float fmax = [[sdArray valueForKeyPath:@"@max.floatValue"] floatValue];
    
    //Ceiling the max value
    int imax = (int)ceilf(fmax);
    
    //Odd check to make even by checking right most bit
    imax = (imax & 0x1) ? imax + 1 : imax;
    
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:(imax / 2) + 1];
    //Assuming all numbers are positive 
    //(should probably just use unsigned int for imax and i)
    for(int i = 0; i <= imax; i +=2)
    {
        [array addObject:[NSString stringWithFormat:@"%d", i]];
    }
    
    NSLog(@"%@", array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You may know this recommendation from Microsoft about the use of exceptions in .NET:
You may know the scriptaculous SlideUp effect . Well, It slides up a div
As you may know, in VS 2008 ctrl + tab brings up a nifty
As you may know, Silverlight 3 doesn't support IMultiValueConverter and... I badly need it.
As some of you may know, use of the LIMIT keyword in MySQL does
As you may know, when we have this code in Javascript : function getName()
As some of you may know in python2.7/3.2 we'll get OrderedDict with PEP372 however
As you may know, in many occasions, there is a need to flag some
If you've used javadoc and then come to doxygen, you may know what I
Long version: Those familiar to the standardization nightmare of the RSS-family, may know that

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.