1

I'm trying to get numbers behind decimal point and use them in another statement.

for example:

int input1;
float x;
if (input1 >= 500)
{
    x = input1 / 500
}

if input1 == 1700 then x would be 3.4. Now I only need .4 to work with it in the next statement. Is there a way to do it?

dandan78
  • 13,328
  • 13
  • 64
  • 78
VSG24
  • 77
  • 7

1 Answers1

0
x = (input1 % 500) * 1.0f / 500

input1 % 500 will take just the remainder of the number and skip the quotient part. Multiplication with 1.0f will convert the number into float and further division with 500 (or better 500.0f) will give you the floating point number.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100