How do I turn an int into a float? [closed] - objective-c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
int *SliderMaximum = V1.TeamAmountAfterSave;
[sliderTeamSelect setmaximum:SliderMaximum];
I need to convert SliderMaximum to a float how do I do this?

NSNumber *yourNumber = [NSNumber numberWithInt: SliderMaximum];
float yourFloat = [yourNumber floatValue];
and you don't need a pointer to int, it's useless, computationally allocate a pointer and write inside address pointer to int is same as allocate a int and write int in it.

Have you tried multiplying it by a float?
CGFloat sliderMaximum = SliderMaximum * 1.0f;

[sliderTeamSelect setmaximum:[[V1.TeamAmountAfterSave] floatValue]];

Related

Invalid Operands to binary expression (NSNumber* __strong and NSNumber*) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
nsnumber *totaldur=0;
totalDur+=(NSNumber*)[dict valueForKey:#"tracktime"];
You can't perform addition on NSnumber for this
NSNumber * totaldur =[NSNumber numberWithInteger:20];
totaldur = [NSNumber numberWithInteger:([number1 integerValue] + [[dict valueForKey:#"tracktime"] integerValue])];
//// first of all convert both numbers to same data type like (nsinteger,int,float) and then apply addition on them and in the end save sum in nsnumber object
Hope it helps

Making A Math Equation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am teaching myself Objective - C and I tried out some code to do a math equation. Can you please tell me what I am doing wrong?
- (IBAction)mathEquation:(id)sender {
int a = 6;
int b = 2;
self.showAnswer.text = int a + int b;
}
Can someone please rewrite to code the correct way and post it? Thank you!
int result = a + b;
self.showAnswer.text = [NSString stringWithFormat:#"%d", result];
In Objective-C, you can't just assign a number to a string, it won't work. As you see in my code, you need to convert from a numerical value into a string. The method [NSString stringWithFormat:] lets you do that, and what kind of number(s) you want to include in the string. E.g. the format expression %d is for an integer value.
Also, once you declared your variables (int a, etc.), you don't need to declare them again, you'll get an error.
I would strongly advice reading up on the basic syntax of Objective-C.

Can the ternary operator be used outside of assignment statements in Objective-C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I know setting a variable conditionally is valid:
someProperty = [anObject aFunctionThatReturnsBool]? #"Yes" : #"No";
This question has an answer that details the use of ternary statements in preprocessor macros
#define statusString (statusBool ? #"Approved" : #"Rejected")
and within a string formatting method
[NSString stringWithFormat: #"Status: %#", (statusBool ? #"Approved" : #"Rejected")]
But what about within any method?
[NSNumber numberWithInt:(aVariableThatCouldBeSet)? 100 : 0)];
And conditional method calling?
[anObject aFunctionThatReturnsBool]? [self doThis] : [self doThat];
Bonus points for any other uses not listed.

NSInteger is NSInteger error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
-(IBAction)button:(id)sender{
If (cardsinplay >= 16){
NSNumber *cardValue = carsAndValue[14];
NSInteger *Value = [cardValue integerValue[;
From what i know this should read the NSNumber from the array and change it into a NSInteger
But i get this error.
Incompatible integer to pointer conversion initialization 'NSInteger*'(aka 'int*') with an expression of type 'NSInteger'(aka 'int*')
-[NSNumber integerValue] returns a NSInteger, not a pointer to one.
NSInteger *Value = [cardValue integerValue];
should be
NSInteger value = [cardValue integerValue];

Put in string int and text [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to put in string int and text.
I have this code: chipsS = [NSString stringWithFormat:#"%i", chips];
What to do?
stringVariable = [NSString stringWithFormat:#"%i - %#", intVariable, stringVariable];