View Full Version : floats...
05-13-2000, 12:27 PM
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???
05-13-2000, 12:51 PM
Use the floor(MyFloat).
If you want to round towards closest int you can use floor(MyFloat + 0.5);
05-13-2000, 02: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;
rounded = (int) x; // yields 15
rounded = x; // this works as well
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.