1. ## rounding question

is it possible to round to the next highest multiple of four? for example:

if i have the values:

1.6, 2.3, 3.4, 3.9 - all of them need to be 4.

4.1, 5.6, 6.3 - all of them need to be 8.

8.1, 9.7, 10 - all of them need to be 12.

etc.

can the ceiling function do this? any suggestions?

keith

2. Depending on how many significant digits you need to worry about, off the top of my head I would do something similar to this (although I'm sure there is an easier way!):
Code:
`x=int(x+3.999999)/4*4;`

3. ## multiple of 4

you could create a function that does it for you

Code:
```int RoundBy4( float flValue )
{
int iFoursInValue;
int iValue;

iValue = flValue + 4;

iFoursInValue = iValue / 4;

iValue = iFoursInValue * 4;

return iValue;
}```
something like this could work .... you probably have to do a little more work to it but it should work....

4. I would do this...

Code:
```#include <math.h>

double d = 2.4;
int i = (int)ceil(2.4);
while((++i)%4); // i is now round to highest multiple of 4```

5. wow you guys are good. i just can't think like that

thanks a bunch.

keith

6. ZMan - yours unfortunately doesn't work for numbers that don't need to be rounded at all. For example, 4.0 should be 4, but yours will say 8. Thats why I added 3.99999 instead of 4.

Jubbas is probably best if you need to worry about an unlimited amount of numbers after the decimal point, but you'll have to change "while((++i)%4)" to "while((i++)%4)" otherwise something like 3.4 will come out as 8.

7. Instead of using 3.99999, use an if. If number % 4 == 0, return number.

8. But you can't use % with floats though.

9. if((int)number % 4 == 0)

Sheesh... figure it out yourself, you've done typecasting before. Do I really have to spoonfeed you?

10. LOL again doesn't work! Try that with 4.1!

11. Oh yeah? well:
Code:
```if((((double)(int)number) == number) && ((int)number % 4 == 0))
return number;
else
return ((double)((int)(number + 4)/4*4));```
HAH!

12. wtf are you thinking? Ever heard of fmod?

13. Yes, but I never knew what it was...