-2

I have a simple calculate code that count about box volume (long * width * height):

ActionListener volListener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        try{
            String L = long.getText();
            String W = width.getText();
            String H = height.getText();
            double parseL = Double.parseDouble(L);
            double parseW = Double.parseDouble(W);
            double parseH = Double.parseDouble(H);
            double volResult = parseL*parseW*parseH;
            txtAreaOut.append("Volume : " + volResult + "\n");
            long.setText("");
            width.setText("");
            height.setText("");
        }catch(NumberFormatException nfe){
            String fault = nfe.getMessage();
            infoBox(fault,  " " + nfe.getClass());
        }
    }
};

If "volResult" return large number, for example 9.0408284742E7, and i want the result like this 9.040.828.474...

How the code?..

  • 1
    Check here, there are answers to display the whole number and/or format a number String if you want commas. http://stackoverflow.com/questions/9602444/force-a-double-to-write-the-whole-number – theguywhodreams Jun 08 '15 at 07:29
  • This is duplicate of so many questions being duplicates of another questions, I don't even know which to pick... – zubergu Jun 08 '15 at 08:38

1 Answers1

0

Use string.format and define number of decimal places. Here I defineded two decimal places.

txtAreaOut.append("Volume : " + String.format( "%.2f",volResult ) + "\n");