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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:00:43+00:00 2026-06-15T19:00:43+00:00

How can I sum multiple doubleValues into a new double? At the moment I

  • 0

How can I sum multiple doubleValues into a new double? At the moment I have tried like this:

double sum = doubleWantToSum1 + doubleWantToSum2 + doubleWantToSum; //etc...

And further, I want to use the result for this equation in

double tooMuch = sum - 100;

Which I want to return 100 minus the total value of my floats. At the moment the only thing this does is to output doubleWantToSum1 – 100. I believe the answer to this rediciously simple, but since I could not find anything on the internet about this I would love it if one of you guys told me.

EDIT, ADDED CODE
Note, I know this is poor and probably uneffective.

//Nummerformatterere - Kinda unødvendig
NSNumberFormatter *fmt1  =  [NSNumberFormatter new]; //Temp
NSNumberFormatter *fmt2  =  [NSNumberFormatter new]; //Methane
NSNumberFormatter *fmt3  =  [NSNumberFormatter new]; //Ethane
NSNumberFormatter *fmt4  =  [NSNumberFormatter new]; //Propane
NSNumberFormatter *fmt5  =  [NSNumberFormatter new]; //n-butane
NSNumberFormatter *fmt6  =  [NSNumberFormatter new]; //i-butane
NSNumberFormatter *fmt7  =  [NSNumberFormatter new]; //n-petane
NSNumberFormatter *fmt8  =  [NSNumberFormatter new]; //i-petane
NSNumberFormatter *fmt9  =  [NSNumberFormatter new]; //n-hexane
NSNumberFormatter *fmt10 =  [NSNumberFormatter new]; //nitrogen
NSNumberFormatter *fmt11 =  [NSNumberFormatter new]; //oxygen

//Float for å få textfieldsene til nummer
double temprature = [fmt1  numberFromString: tempratureText.text].doubleValue;
double methane    = [fmt2  numberFromString: methaneText.text   ].doubleValue;
double ethane     = [fmt3  numberFromString: ethaneText.text    ].doubleValue;
double propane    = [fmt4  numberFromString: propaneText.text   ].doubleValue;
double nbutane    = [fmt5  numberFromString: nbutaneText.text   ].doubleValue;
double ibutane    = [fmt6  numberFromString: ibutaneText.text   ].doubleValue;
double npetane    = [fmt7  numberFromString: npetaneText.text   ].doubleValue;
double ipetane    = [fmt8  numberFromString: ipetaneText.text   ].doubleValue;
double nhexane    = [fmt9  numberFromString: nhexaneText.text   ].doubleValue;
double nitrogen   = [fmt10 numberFromString: nitrogenText.text  ].doubleValue;
double oxygen     = [fmt11 numberFromString: oxygenText.text    ].doubleValue;

//Floats og formatters for underflow, overflow
double sum = (methane + ethane + propane + nbutane + ibutane + npetane + ipetane + nhexane + nitrogen + oxygen);
double overflowPart = 100 - sum;
double underflowPart = sum - 100;

NSNumber *underFlow = [[NSNumber alloc]initWithDouble:underflowPart];
NSNumberFormatter *underFlowResult = [[NSNumberFormatter alloc] init];
underFlowResult.numberStyle = NSNumberFormatterDecimalStyle;
[underFlowResult setNumberStyle:NSNumberFormatterDecimalStyle];
[underFlowResult setMaximumFractionDigits:2];
NSString *formattedUnderFlow = [underFlowResult stringFromNumber:(NSNumber*)underFlow];

NSNumber *overFlow = [[NSNumber alloc]initWithDouble:underflowPart];
NSNumberFormatter *overFlowResult = [[NSNumberFormatter alloc] init];
overFlowResult.numberStyle = NSNumberFormatterDecimalStyle;
[overFlowResult setNumberStyle:NSNumberFormatterDecimalStyle];
[overFlowResult setMaximumFractionDigits:2];

NSString *formattedOverFlow = [overFlowResult stringFromNumber:(NSNumber*)overFlow];

//Floats for variabler til ligningen
double Xi = 1;
double Mi = 2;
double Vi = 3;
double Vc = 4;

//Ligningen for å regne ut density
double over1 = Xi * Mi;
double under1 = Xi * Vi - Vc;

//=RESULT=
double result =  over1 / under1;

/*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED FLOATER----------*/

NSString *resultString = [[NSString alloc]initWithFormat:@"D = %f", result];
NSString *overflowString = [[NSString alloc]initWithFormat:@"Total %@ greater than 100 %", formattedOverFlow ];
NSString *underflowString = [[NSString alloc]initWithFormat:@"Total %@ less than 100 %", formattedUnderFlow];

/*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED STRINGS----------*/
/*
if (temprature == 0 || methane == 0 || ethane == 0 || propane == 0 || nbutane == 0 || ibutane == 0 || oxygen == 0 || npetane == 0 || ipetane == 0 || nhexane == 0 || nitrogen == 0)
{
    outputText.text = @"Please enter all values";
} */
if (underflowPart == 100)
{
    outputText.text = @"Start by entering values above";
}
if (sum == 100)
{
    outputText.text = resultString;
}

if (sum > 100)
{
    outputText.text = overflowString;
}

if (sum < 100)
{
    outputText.text = underflowString;
}
/*----------STREK FORDI DET ER CHILL OG JEG ER FERDIG MED 'if'----------*/
  • 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-15T19:00:45+00:00Added an answer on June 15, 2026 at 7:00 pm

    It has not yet been explicitly said in the comments that the way you are summing the numbers in your code is correct. What the comments are implying is that the numbers you are summing are wrong, and you should log them to see what they are.

    As well, you could save some code (eliminate your number formatters) by using:

    double temprature = [tempratureText.text doubleValue];
    

    instead of

    double temprature = [fmt1  numberFromString: tempratureText.text].doubleValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you pass variables into subqueries, like so? SELECT users.id AS id, (SELECT SUM(total)
Why can't we use return keyword inside ternary operators in C, like this: sum
I have a loop like the following, can I do the same using multiple
I have a sql query that looks like this: SELECT SUM(A) AS expr1 FROM
I have this table: Movies (ID, Genre) A movie can have multiple genres, so
With SUM for instance, I can do things like: =SUM(F5:F7,F6:F8,A1,E7:G7,F7,2,7) Which takes multiple ranges
I have the following formula: =ArrayFormula(SUM(Morten!$M4:$M400)) How can I replace Morten with the contents
I have this query: SELECT p.text,se.name,s.sub_name,SUM((p.volume / (SELECT SUM(p.volume) FROM phrase p WHERE p.volume
I have multiple product sales in different markets, and I need to sum up
In Scala one can write (curried?) functions like this def curriedFunc(arg1: Int) (arg2: String)

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.