get Discount value format as 0.## - Java java.text

Java examples for java.text:DecimalFormat

Description

get Discount value format as 0.##

Demo Code


//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);
    }
}

Related Tutorials