• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

DecimalFormat

Hi
I am trying to write code statements to create a DecimalFormat object that will round a formatted value to 4 decimal places. Then I need to write a statement that uses that object to print the value of result, properly formatted in Java Programming

0
Ansary100
Asked:
Ansary100
1 Solution
 
suprapto45Commented:
Hi,

Please check this URL

http://www.javaalmanac.com/egs/java.text/FormatNum.html

Regards
Dave
0
 
TheC2Commented:
Here is some code that does this:

    DecimalFormat df;
    double x = 486.2536879;
   
    df = new DecimalFormat("0.####");
    this.setTitle(df.format(x));

If you want to change to format you can change the format string that is passed to the DecimalFormat constructor.
You can find help on the format string here: http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html.

Good luck!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now