int and float - will this work?

This is a discussion on int and float - will this work? within the C Programming forums, part of the General Programming Boards category; I've got this code and I'm trying to multiply something times 1.3 (float value) Anyways, P is defined: int p=0; ...

1. int and float - will this work?

I've got this code and I'm trying to multiply something times 1.3 (float value)

Anyways, P is defined:

int p=0;

Here's the code:

Code:
``` for(pos = (minimum+(p*1.3)); pos < (maximum-p); pos += 1)
{
myservo.write(pos);
delay(3);
}

for(pos = (maximum-p); pos>=(minimum+(p*1.3)); pos-=1)
{
myservo.write(pos);
delay(3);
}```
I'm looking to multiply the int value (non decimal number) times 1.3 as in the above code.

Will this work? I don't need a float for resolution... just an integer but I'd like to multiply by float values.

Just unsure of how all of the float and integer values work together.

2. Yeah, it should work.

But are you working on some kind of embedded processor lacking floating point hardware?
In which case, it could be extremely expensive to calculate.

If you've got the integer head room, you could always do p * 13 / 10

3. If you multiply an int by a float, the int will automatically be converted to a float for you for the multiplication operation. Of course, once you set the float result to your int pos, the decimal portion of the number will be truncated (e.g. 4.3 will become 4, 7.8 will become 7).

4. Great thanks guys! And it worked in real life with the hardware I'm working on (Arduino Microcontroller and a servo).