Multiply Int by a Float?

Okay So I have a durabilityInt = 0; and a modifiedDurability = .55; and an itemEquipInt = 0;

The itemEquipInt changed based on a dropdown menu that the player selects #1-60
For each # ex: 2 then modifiedDurability is multiplied by 2. This script all works fine. What I can’t get to work properly is multiplying the modifiedDurability by durModifier ← (1.5)

How do I Multiply modifiedDurability (integer) by durModifier (float)?

What isn't working? Usually a float times an int will create a float like so. float a = int b * float c;

Wasn't working for me and still isn't but I compromised and just changed the int's to floats and multipled floats by floats. it all works the same and won't mess up what I am doing so ty for the help tho.

2 Answers

2

Finding this question as I’m doing a search here.
You have probably moved on and finished your project by now.
Anyway, in case someone else finds this question, here’s some explanation :

there is no multiply operator for float and int, and while a float cannot be implicitly converted to an int, an int is implicitly converted to a float. So the compiler will convert the int to a float, and the result will be a float. You need to cast is back to an int.

int myInt = 2;
float myFloat = 2.7f;
int result = (int)(myInt * myFloat);

Yes, the OP was last online Nov. 2014, so it's unlikely that he actually sees the answer or is still in need of an answer. Since you put much efford into the answer i'll accept the answer and close the question.

float YourAnswerIs = modifiedDurability * durModifier;