Jump to content
  • Advertisement
Sign in to follow this  
CRACK123

printing a double value to decimal places in java 1.4

This topic is 4466 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

Hi, How do I print a value to 2 decimal places in java if the value is a type of double I tried DecimalFormat by doing
String str = Double.toString(value);
DecimalFormat dec = new DecimalFormat(str);
dec.setMaximumFractionDigits(2);
String res = dec.toString();


But this does not seem to work. Thanks

Share this post


Link to post
Share on other sites
Advertisement

import java.text.*;

public class Test
{
public static void main(String[] args)
{
double d = 1.234567;
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(d));
}
}

Share this post


Link to post
Share on other sites

This topic is 4466 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!