Problem with numbers... again

Now I got the opposite problem of what I had yesterday.

I got a number between 1 and 1000.
This number needs to be seperated into 4 different numbers.

1337

needs to become 1, 3, 3, 7.

I’ve tried dividing:

Like so:

Number 1 = 1337 / 1000 = 1,337

Number 2 = 1337 / 100 = 13,37 (here’s the problem)

I’m stuck with 13,37.
I figured, if I write
int x = 0;
if ((1337 / 100) >= 10 && (1337 / 100) < 20)
{
x = 1;
}

and have number 2 = (1337-100)-(10 * x);

But doing this 10 times for every digits seems an awful lots of waste of time and coding space to do for something that should be alot simpler.

Short said: I need to round off the number, down. I need to get rid of whatever there is of decimals and just round every decimal down to 0.

Suggestions?

Maybe you should set a different goal. 1337 is not between 1 and 1000.

Number 2 = 1337 / 100 = 13,37

Only if you use floating-point division

OK, so here it is:

digit0=number%10;
digit1=number/10%10;
digit2=number/10/10%10;
digit3=number/10/10/10%10;

I think this is very understandable once you read up on % operator.

Thanks, but I actually figured it out before your post, ludr.

I was fooling myself until AWOL replied.
I made the wrong calculations by thinking the variable would be floating.

Once AWOL said it wasn’t, the rest was pretty straight forward.

This is one of the paragraphs: (it works btw)

if ( counter >= 1000 && counter < 10000)
{
input1 = analogvalue / 1000;
input2 = (analogvalue / 100) - (input1 * 10 );
input3 = (analogvalue / 10) - (input1 * 100) - (input2 * 10);
input4 = (analogvalue - (input1 * 1000) - (input2 * 100) - (input3 * 10));
}

Glad you figured it out. Still if you use % it will look easier.