Archived

This topic is now archived and is closed to further replies.

wolfbane

working with floats

Recommended Posts

Quick and dirty solution:

float round(float val, int place)
{
float temp = ((float) ((int) (val*place)))/place;

val -= temp;
if(val*place > 0.5)
temp += 1.0/place;

return temp;
}

Usage:

float var = round(1.2399999, 100) // var = 1.24

- mongrelprogrammer

Share this post


Link to post
Share on other sites