How can I format a number in java so that only two numbers are displayed after the decimal point?
I have tried using DecimalFormat with no luck.
Here is the code I used.This doesn't work as I got a result of "£ 509.97003"Code:float newTotPrice = totPrice + Double.valueOf(myProduct.getPrice()).floatValue(); //For formatting a number DecimalFormat df = new DecimalFormat("#.00"); //Format 'newTotPrice' so that only two digits are shown after the decimal point df.format(newTotPrice); //Show total price lblTotPrice.setText("£ " + newTotPrice);




Reply With Quote