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:
Code :int floatToDiv10( float in ) { return (((int)in)/10) * 10; } void main() { printf( "result:%d\n", floatToDiv10( 35.297f ) ); }
um shouldn't the answer be 40?? being _NEAREST_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?
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).]