Jump to content
  • Advertisement

Archived

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

wolfbane

working with floats

This topic is 5894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how IN JAVA do you cut the float point decimal places to the hundreth place? how do I get 1.23999999999 to be 1.24?

Share this post


Link to post
Share on other sites
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!