to Decimal Format String as 0.### - Java java.lang

Java examples for java.lang:double Format

Description

to Decimal Format String as 0.###

Demo Code


//package com.java2s;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] argv) {
        double doubleVal = 42.45678;
        System.out.println(toDecimalFormatString(doubleVal));
    }/* w ww.j av  a  2  s  .  co m*/

    public static String toDecimalFormatString(double doubleVal) {
        DecimalFormat df = new DecimalFormat("0.###");
        return df.format(doubleVal);
    }
}

Related Tutorials