[SOLVED] How to make a calculation with floats and integers

With intDegrees = 45 en intStepsPerRevolution=2048 it seemed that

steps1 = intDegrees /360 * intStepsPerRevolution; (delivers 0)
steps2 = intDegrees * intStepsPerRevolution / 360; (delivers 73.00)

I should expect 256

What are I doing wrong?

const int intStepsPerRevolution = 2048;  //this is valid the 28BYJ-48
const int gearratio = 32;             //this is valig the 28BYJ-48
#define STEPS 64                      //motor makes 64 steps per revolution

int intDegrees;
int n =0;
float steps1;
float steps2;
//==========================================================================
void setup()
{
  Serial.begin(9600);
 
}

//==========================================================================
void loop()
{
  
  //Rotate x degrees
  intDegrees= 45;
  steps1 = intDegrees /360 * intStepsPerRevolution;
  steps2 = intDegrees * intStepsPerRevolution / 360;
  Serial.print(intDegrees /360 * intStepsPerRevolution); Serial.print ("\t"); Serial.print (steps1); Serial.print ("\t"); Serial.println (steps2);
  delay(2000);
  
}
  steps1 = intDegrees /360 * intStepsPerRevolution;

In this programming language, integer divided by integer yields an integer.
Mathematically, 45 divided by 360 is 0.125, but our system stops calculating at the decimal point and uses 0 as the result of the division. Zero times anything is zero, so the multiplication then gives zero.

  steps2 = intDegrees * intStepsPerRevolution / 360;

An int only goes up to 32767. Therefore, 45 * 2048 will not fit in an int, and thus the multiplication will give a garbage result. The division will give a garbage result because it is using the garbage result from the multiplication.

Try:

  steps1 = intDegrees /360.0 * intStepsPerRevolution;

in which the decimal point forces floating-point division, or

  steps2 = ((long)intDegrees) * intStepsPerRevolution / 360;

in which the multiplication is done using a datatype big enough to hold the product.

Thank you Odometer.

I used now:

fltSteps1 = (float)intDegrees /360 * intStepsPerRevolution;

With this float-conversion I don't worry about other declarations and the order of variables in the formula.