Java examples for java.text:DecimalFormat
get Discount value format as 0.##
//package com.java2s; import java.text.DecimalFormat; public class Main { public static void main(String[] argv) throws Exception { double num = 2.45678; System.out.println(getDiscount(num)); }/*from ww w .jav a2 s . co m*/ public static String getDiscount(double num) { double per = num / 10.00; DecimalFormat dft = new DecimalFormat("0.##"); return dft.format(per); } }