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?
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?
not really an opengl question, but simple enough:
int floatToDiv10( float in ) {
return (((int)in)/10) * 10;
}void main() {
printf( "result:%d
", floatToDiv10( 35.297f ) );
}
Originally posted by Schlogenburg:
[b]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?[/b]
um shouldn’t the answer be 40?? being NEAREST
Then you just have to change it to
int floatToDiv10( float in ){
return (((int)(in+5.0f))/10)*10;
}
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).]