PDA

View Full Version : floats...



CyBBe
05-13-2000, 11:27 AM
Simple question, of the record (NOT an opengl question...). I need to know how I round a float, if it's 15.00000001 and I want it to be rounded to 15, how do I do???

Thanx...

Humus
05-13-2000, 11:51 AM
Use the floor(MyFloat).

If you want to round towards closest int you can use floor(MyFloat + 0.5);

Eric Chan
05-13-2000, 01:24 PM
If you're dealing with strictly non-negative numbers, then you can just let C truncate it for you if you do auto-type conversion to an int, for example:

float x = 15.0000001;
int rounded;

rounded = (int) x; // yields 15
rounded = x; // this works as well

ec