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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:58:39+00:00 2026-05-20T13:58:39+00:00

I have a few float s which I convert to NSNumber s and add

  • 0

I have a few floats which I convert to NSNumbers and add to an array, then sort in numerical order.

I then take the original floats and convert those to NSNumbers, but if I try to compare them if(numinarray = newnum){ it never goes anywhere. When I NSLog() out the value, the values match:

float distance  = [barnardCastle distanceFromLocation:loc1] / 1000;
float distance2 = [billingham distanceFromLocation:loc1] / 1000;
float distance3 = [bishopAukland distanceFromLocation:loc1] / 1000;
float distance4 = [cockerton distanceFromLocation:loc1] / 1000;
float distance5 = [darlington distanceFromLocation:loc1] / 1000;
float distance6 = [guisborough distanceFromLocation:loc1] / 1000;
float distance7 = [hartlepool distanceFromLocation:loc1] / 1000;
float distance8 = [middlesbrough distanceFromLocation:loc1] / 1000;
float distance9 = [northallerton distanceFromLocation:loc1] / 1000;
float distance10 = [redcar distanceFromLocation:loc1] / 1000;
float distance11 = [stockton distanceFromLocation:loc1] / 1000;
float distance12 = [yarm distanceFromLocation:loc1] / 1000;


NSArray *nums, *sorted;

nums = [NSArray arrayWithObjects:
        [NSNumber numberWithFloat:distance],
        [NSNumber numberWithFloat:distance2],
        [NSNumber numberWithFloat:distance3],
        [NSNumber numberWithFloat:distance4],
        [NSNumber numberWithFloat:distance5],
        [NSNumber numberWithFloat:distance6],
        [NSNumber numberWithFloat:distance7],
        [NSNumber numberWithFloat:distance8],
        [NSNumber numberWithFloat:distance9],
        [NSNumber numberWithFloat:distance10],
        [NSNumber numberWithFloat:distance11],
        [NSNumber numberWithFloat:distance12],
        nil];

sorted = [nums sortedArrayUsingSelector:@selector(compare:)];

NSLog(@"nums sorted");
NSLog(@"distance is %f",distance);
NSNumber *intdist = [NSNumber numberWithFloat:distance]; 
NSNumber *intdist2 = [NSNumber numberWithFloat:distance2];
NSNumber *intdist3 = [NSNumber numberWithFloat:distance3];
NSNumber *intdist4 = [NSNumber numberWithFloat:distance4];
NSNumber *intdist5 = [NSNumber numberWithFloat:distance5];
NSNumber *intdist6 = [NSNumber numberWithFloat:distance6];
NSNumber *intdist7 = [NSNumber numberWithFloat:distance7];
NSNumber *intdist8 = [NSNumber numberWithFloat:distance8];
NSNumber *intdist9 = [NSNumber numberWithFloat:distance9];
NSNumber *intdist10 = [NSNumber numberWithFloat:distance10];
NSNumber *intdist11 = [NSNumber numberWithFloat:distance11];
NSNumber *intdist12 = [NSNumber numberWithFloat:distance12];
NSLog(@"int dist %@",intdist);
NSLog(@"int dist2 %@",intdist2);
NSLog(@"int dist3 %@",intdist3);
NSLog(@"int dist4 %@",intdist4);
NSLog(@"int dist5 %@",intdist5);
NSLog(@"int dist6 %@",intdist6);
NSLog(@"int dist7 %@",intdist7);
NSLog(@"int dist8 %@",intdist8);
NSLog(@"int dist9 %@",intdist9);
NSLog(@"int dist10 %@",intdist10);
NSLog(@"int dist11 %@",intdist11);
NSLog(@"int dist12 %@",intdist12);


nearestLoc = [[NSMutableArray alloc]init];

NSLog(@"about to loop");
for (int i=0; i < 12; i++) {
    Branches *branches = [[Branches alloc]init];
    NSLog(@"looping");

    NSNumber *index = [sorted objectAtIndex:i];

    NSNumber *intdist = [NSNumber numberWithFloat:distance]; 
    NSNumber *intdist2 = [NSNumber numberWithFloat:distance2];
    NSNumber *intdist3 = [NSNumber numberWithFloat:distance3];
    NSNumber *intdist4 = [NSNumber numberWithFloat:distance4];
    NSNumber *intdist5 = [NSNumber numberWithFloat:distance5];
    NSNumber *intdist6 = [NSNumber numberWithFloat:distance6];
    NSNumber *intdist7 = [NSNumber numberWithFloat:distance7];
    NSNumber *intdist8 = [NSNumber numberWithFloat:distance8];
    NSNumber *intdist9 = [NSNumber numberWithFloat:distance9];
    NSNumber *intdist10 = [NSNumber numberWithFloat:distance10];
    NSNumber *intdist11 = [NSNumber numberWithFloat:distance11];
    NSNumber *intdist12 = [NSNumber numberWithFloat:distance12];
    NSLog(@"int dist %@",intdist);
    NSLog(@"int dist2 %@",intdist2);
    NSLog(@"int dist3 %@",intdist3);
    NSLog(@"int dist4 %@",intdist4);
    NSLog(@"int dist5 %@",intdist5);
    NSLog(@"int dist6 %@",intdist6);
    NSLog(@"int dist7 %@",intdist7);
    NSLog(@"int dist8 %@",intdist8);
    NSLog(@"int dist9 %@",intdist9);
    NSLog(@"int dist10 %@",intdist10);
    NSLog(@"int dist11 %@",intdist11);
    NSLog(@"int dist12 %@",intdist12);
    NSLog(@"index %@",index);


    if (index == intdist) {

        branches.branchLoc = @"Barnard Castle";
        branches.distance = distance;
        [nearestLoc addObject:branches];
        NSLog(@"adding barnard castle");
    }

    if (index == intdist2) {
        branches.branchLoc = @"Billingham";
        branches.distance = distance2;
        [nearestLoc addObject:branches];

        NSLog(@"adding billingham");
    }

Am I missing something with using NSNumber? If so, how would you get arround it?

  • 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-20T13:58:40+00:00Added an answer on May 20, 2026 at 1:58 pm

    Instead of using ==, call compare: or isEqualToNumber:. When you use ==, you are comparing the pointers.

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

Sidebar

Related Questions

I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have found this example on StackOverflow: var people = new List<Person> { new
Let say I have the following desire, to simplify the IConvertible's to allow me
There doesn't seem to be any tried and true set of best practices 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.