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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:54:30+00:00 2026-06-13T00:54:30+00:00

I’m making a converter app, and after realising I would have to type about

  • 0

I’m making a converter app, and after realising I would have to type about 200 lines of code to get it working with more than 5 units converted, I should have a better conversion calculation.

What I have currently is a ifelse that find out what units i selected from the wheel, a sting to find out what it should answer and a float to calculate. It looks like this atm:

 #import "MainViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController;

@synthesize _convertFrom, _convertTo, _convertRates;
@synthesize inputText, picker, resultLabel;
- (void)viewDidLoad
{
    [super viewDidLoad];
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
        _convertFrom = @[@"MTPA", @"MMcf/day",
        @"Mill.Sm3/day", @"MMBTU", @"Boe/day"];

        _convertRates = @[ @1.0f, @2.0f, @3.0f,
        @4.0f, @5.0f];

        _convertTo = @[@"MTPA", @"MMcf/day",
        @"Mill.Sm3/day", @"MMBTU", @"Boe/day"];

    _convertRates = @[ @1.0f, @2.0f, @3.0f,
    @4.0f, @5.0f];
}
}
- (void)didReceiveMemoryWarning
{
 [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
//dont forget to put something in here later
}


-(IBAction)textFieldReturn:(id)sender
{
    [sender resignFirstResponder];
}
-(IBAction)backgroundTouched:(id)sender
{
    [inputText resignFirstResponder];
}


#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:    (NSInteger)component
{
    if (component == 0)  {
        return [_convertFrom count];
    }
    return [_convertTo count];
}


- (NSString *) pickerView: (UIPickerView *)pickerView
          titleForRow:(NSInteger)row
         forComponent:(NSInteger)component
{
    if (component == 0) {
        return [_convertFrom objectAtIndex:row];
    }
    return [_convertTo objectAtIndex:row];
}




#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
    float convertFrom = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:0]] floatValue];
    float convertTo = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1]] floatValue];
    float input = [inputText.text floatValue];
float to = convertTo;
float from = convertFrom;
float convertValue = input;

float MTPATilMTPAFloat               = convertValue * 1;
float MTPATilMMScfdayFloat           = convertValue * 133.425;
float MTPATilMillSm3dayFloat         = convertValue * 3.779735;
float MTPATilMMBTUFloat              = convertValue * 4;
float MTPATilboedayFloat               = convertValue * 5;

float MMScfdayTilMTPAFloat           = convertValue * 0.5;
float MMScfdayTilMMScfdayFloat       = convertValue * 1;
float MMScfdayTilMillSm3dayFloat     = convertValue * 6;
float MMScfdayTilMMBTUFloat          = convertValue * 7;
float MMScfdayTilboedayFloat           = convertValue * 8;

float MillSm3dayTilMTPAFloat = convertValue / 1;
float MillSm3dayTilMMScfdayFloat = convertValue / 2;
float MillSm3dayTilMillSm3dayFloat = convertValue / 3;
float MillSm3dayTilMMBTUFloat = convertValue / 4;
float MillSm3dayTilboedayFloat = convertValue / 5;

float MMBTUTilMTPAFloat = convertValue * 2;
float MMBTUTilMMScfdayFloat = convertValue * 2;
float MMBTUTilMillSm3dayFloat = convertValue * 2;
float MMBTUTilMMBTUFloat = convertValue * 2;
float MMBTUTilboeday = convertValue * 2;

float boedayTilMTPAFloat = convertValue * 3;
float boedayTilMMScfdayFloat = convertValue * 3;
float boedayTilMillSm3dayFloat = convertValue * 3;
float boedayTilMMBTUFloat = convertValue * 3;
float boedayTilboeday = convertValue * 3;





NSString *MTPATilMTPA = [[NSString alloc ] initWithFormat:
                         @" %f MTPA = %f MTPA", convertValue, MTPATilMTPAFloat];

NSString *MTPATilMMScfday = [[NSString alloc ] initWithFormat:
                             @" %f MTPA = %f MMScf/day", convertValue, MTPATilMMScfdayFloat];

NSString *MTPATilMillSm3day = [[NSString alloc] initWithFormat:
                               @" %f MTPA = %f Mill.SM3/day", convertValue, MTPATilMillSm3dayFloat];

NSString *MTPATilMMBTU = [[NSString alloc] initWithFormat:
                          @" %f MTPA = %f MMBTU", convertValue, MTPATilMMBTUFloat];

NSString *MTPATilboeday = [[NSString alloc] initWithFormat:
                         @" %f MTPA = %f Boe/day", convertValue, MTPATilboedayFloat];




NSString *MMScfdayTilMTPA = [[NSString alloc] initWithFormat:
                             @" %f MMScfday = %f MTPA", convertValue, MMScfdayTilMTPAFloat];

NSString *MMScfdayTilMMScfday = [[NSString alloc] initWithFormat:
                                 @" %f MMScfday = %f MMScfday", convertValue, MMScfdayTilMMScfdayFloat];

NSString *MMScfdayTilMillSm3day = [[NSString alloc] initWithFormat:
                                   @" %f MMScfday = %f MillSm3day", convertValue, MMScfdayTilMillSm3dayFloat];

NSString *MMScfdayTilMMBTU = [[NSString alloc] initWithFormat:
                              @" %f MMScfday = %f MMBTU", convertValue, MMScfdayTilMMBTUFloat];

NSString *MMScfdayTilboeday = [[NSString alloc] initWithFormat:
                             @" %f MMScfday = %f Boe/day", convertValue, MMScfdayTilboedayFloat];




NSString *MillSm3dayTilMTPA = [[NSString alloc] initWithFormat:
                               @" %f MillSm3day = %f MTPA", convertValue, MillSm3dayTilMTPAFloat];



if (from == 1) {
    if (to == 1) {
        resultLabel.text = MTPATilMTPA;
    }
    else if (to == 2) {
        resultLabel.text = MTPATilMMScfday;
    }
    else if (to == 3) {
        resultLabel.text = MTPATilMillSm3day;
    }
    else if (to == 4) {
        resultLabel.text = MTPATilMMBTU;
    }
    else if (to == 5) {
        resultLabel.text = MTPATilboeday;
    }
}
else if (from == 2) {
    if (to == 1) {
        resultLabel.text = MMScfdayTilMTPA;
    }
    else if (to == 2) {
        resultLabel.text = MMScfdayTilMMScfday;
    }
    else if (to == 3) {
        resultLabel.text = MMScfdayTilMillSm3day;
    }
    else if (to == 4) {
        resultLabel.text = MMScfdayTilMMBTU;
    }
    else if (to == 5) { 
        resultLabel.text = MMScfdayTilboeday;
    }
}
}

As you can see, a huge mess with alot of more code needed if I want more units.

When I realised that, i tried to calculate it by using a commmon variable that I convert everything into, and then convert back into a output unit. Think of it with lenght calculation. The common variable i want everything to be converted to first, is meters. so 1 meters = 1, 1 cm = 0.01 and 1 mm = 0.001. So, if I wanted to calculate, i would use.

unitIwantToConvertToComparedTo1Meter = 0.5 (of 1 meter)
result = from * to * input * unitIwantToConvertToComparedTo1Meter.

Which, surprisingly, works.
As used here:

#import "MainViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController;

@synthesize _convertFrom, _convertTo, _convertRates;
@synthesize inputText, picker, resultLabel;
- (void)viewDidLoad
{
    [super viewDidLoad];
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
        _convertFrom = @[@"Kubikk M", @"Kubikk CM",
        @"Kubikk MM", @"MMBTU", @"Boe/day"];

        _convertRates = @[ @1.0f, @0.01f, @0.001f,
        @4.0f, @5.0f];

    _convertTo = @[@"Kubikk M", @"Kubikk CM",
    @"Kubikk MM", @"MMBTU", @"Boe/day"];

    _convertRates = @[ @1.0f, @0.01f, @0.001f,
    @4.0f, @5.0f];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
//dont forget to put something in here later
}


    -(IBAction)textFieldReturn:(id)sender
    {
    [sender resignFirstResponder];
}
-(IBAction)backgroundTouched:(id)sender
{
    [inputText resignFirstResponder];
}


#pragma mark -
#pragma mark PickerView DataSource

- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0)  {
    return [_convertFrom count];
}
return [_convertTo count];
}


- (NSString *) pickerView: (UIPickerView *)pickerView
          titleForRow:(NSInteger)row
         forComponent:(NSInteger)component
{
    if (component == 0) {
        return [_convertFrom objectAtIndex:row];
    }
    return [_convertTo objectAtIndex:row];
}




#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
    float convertFrom = [[_convertRates objectAtIndex:[pickerView   selectedRowInComponent:0]] floatValue];
float convertTo = [[_convertRates objectAtIndex:[pickerView selectedRowInComponent:1]] floatValue];
float input = [inputText.text floatValue];
float to = convertTo;
float from = convertFrom;
float convertValue = input;

float kubikkfot = 0.1;

float result = from * convertValue * kubikkfot;



NSString *resultString = [[NSString alloc ] initWithFormat:
                         @" %f MTPA = %f MTPA", convertValue, result];
resultLabel.text = resultString;
}

The problem with this is
1. My brain is having a meltdown trying to figure out how
2. I would like to have a custom label for every answer, where it says what unit i converted from and to. How can i implement this?

So, can anyone give me a hand with some better calculation code?

  • 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-13T00:54:31+00:00Added an answer on June 13, 2026 at 12:54 am

    Dude use C arrays to create an nxn matrix of conversions. Then just have one array with unit names in it. Done and done. If you don’t know what a matrix is, then you have more theory to learn.

    It goes like this. C is your conversion matrix:

           inch      meter
          +-----------------
    inch  | 1        0.0254
    meter | 39.3701  1
    

    So if x is in inches then C[inch][meter] * x is the same length in meters.

    And C[i][j] * C[j][i] == 1. Always.

    You will have a different conversion matrix for each quantity that you are measuring. That is, you will have one for heat, one for time, one for distance (the example above), one for energy, one for force… etc. Good luck!

    • 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’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.