# Thread: converting float to integer and nearest 10? like so

1. ## converting float to integer and nearest 10? like so

say I have float:
float a = 35.297;

I want to convert to integer and to the nearest 10 like so:
results in b:

30

how can I do this to any given float?

2. ## Re: converting float to integer and nearest 10? like so

not really an opengl question, but simple enough:

Code :
```int floatToDiv10( float in ) {
return (((int)in)/10) * 10;
}

void main() {
printf( "result:%d\n", floatToDiv10( 35.297f ) );
}```

3. ## Re: converting float to integer and nearest 10? like so

Originally posted by Schlogenburg:
say I have float:
float a = 35.297;

I want to convert to integer and to the nearest 10 like so:
results in b:

30

how can I do this to any given float?
um shouldn't the answer be 40?? being _NEAREST_

4. ## Re: converting float to integer and nearest 10? like so

Then you just have to change it to

int floatToDiv10( float in ){
return (((int)(in+5.0f))/10)*10;
}

5. ## Re: converting float to integer and nearest 10? like so

That only works for positve numbers. Just use 'int rint(float f)' from the maths library.

[This message has been edited by foobar (edited 07-15-2000).]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•