current Format Four decimal - Java java.lang

Java examples for java.lang:double Format

Description

current Format Four decimal

Demo Code


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

public class Main {
    public static String currentFormatFour(BigDecimal current) {
        DecimalFormat doubleFormat = new DecimalFormat();
        doubleFormat.applyPattern("##0.0000");
        String formatCur = doubleFormat.format(current);
        return formatCur;
    }//from   w w w . j  a va  2 s  .c om

    public static String currentFormatFour(int current) {
        DecimalFormat doubleFormat = new DecimalFormat();
        doubleFormat.applyPattern("##0.0000");
        String formatCur = doubleFormat.format(current);
        return formatCur;
    }

    public static String currentFormatFour(float current) {
        DecimalFormat doubleFormat = new DecimalFormat();
        doubleFormat.applyPattern("##0.0000");
        String formatCur = doubleFormat.format(current);
        return formatCur;
    }

    public static String currentFormatFour(double current) {
        DecimalFormat doubleFormat = new DecimalFormat();
        doubleFormat.applyPattern("##0.0000");
        String formatCur = doubleFormat.format(current);
        return formatCur;
    }

    public static String currentFormatFour(String current) {
        DecimalFormat doubleFormat = new DecimalFormat();
        doubleFormat.applyPattern("##0.0000");
        BigDecimal bdCurrent = new BigDecimal(current);
        String formatCur = doubleFormat.format(bdCurrent);
        return formatCur;
    }
}

Related Tutorials