Jump to content
  • Advertisement

Archived

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

wolfbane

[java] working with floats

This topic is 5897 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 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
You have to use the DecimalFormat.
Here is an example


    
import java.text.DecimalFormat; // Import DecimalFormat

public class it
{
public static void main(String args[])
{
// Used to set the decimalFormat to two decimal places

DecimalFormat twoDigits = new DecimalFormat ("0.00");

float num = 1.23999999999999;

// Print out the number and force it to two decimal places

System.out.println(twoDigits.format(num));
}
}


Hope this helps

[edited by - Loves_Java on May 1, 2002 6:17:54 PM]

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!