February 01, 2012

Float value constraint to two decimal points


How to Format a double value to 2 decimal places

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

Description : How to confined the value in java upto two decimal places. Decimal value allowed only upto two spaces.

Facebook comments