Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

In this page you can find the example usage for java.text DecimalFormat DecimalFormat.

Prototype

public DecimalFormat() 

Source Link

Document

Creates a DecimalFormat using the default pattern and symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static float formatFloat(float value) {
    DecimalFormat df = new DecimalFormat();
    String style = "0.0";
    df.applyPattern(style);//from  w w w  . j  a  v  a2  s.c  om
    return Float.valueOf(df.format(value));
}

From source file:Main.java

public static String getFormattedLocationString(double[] coordinates, String address) {
    DecimalFormat df = new DecimalFormat();
    return address + " " + "Lat: " + String.format("%.4f", coordinates[0] / 1E6) + " Lon: "
            + String.format("%.4f", coordinates[1] / 1E6);
}

From source file:Main.java

public static String formatNum(double value) {
    String retValue = null;/*from  w ww .  jav  a 2s .  co  m*/
    DecimalFormat df = new DecimalFormat();
    df.setMinimumFractionDigits(0);
    df.setMaximumFractionDigits(2);
    retValue = df.format(value);
    retValue = retValue.replaceAll(",", "");
    return retValue;
}

From source file:Main.java

public static String MybigdecimalToString(BigDecimal myBigD) {
    myBigD = myBigD.setScale(2);//from w  ww  .  j a  v a 2 s  . c  o m
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    return df.format(myBigD);
}

From source file:Main.java

public static String formatNumber(int number) {
    DecimalFormat formatter = new DecimalFormat();
    DecimalFormatSymbols symbol = new DecimalFormatSymbols();
    symbol.setGroupingSeparator('.');
    formatter.setDecimalFormatSymbols(symbol);
    return formatter.format(number);
}

From source file:Main.java

public static String formatMoney(double amount) {
    DecimalFormat df = new DecimalFormat();
    df.applyPattern("##,###0.00");
    return df.format(amount);
}

From source file:Main.java

public static String formatPercent(BigDecimal number) {
    String result = "0";

    if (number != null) {
        number = number.multiply(new BigDecimal("100"));
        DecimalFormat formatter = new DecimalFormat();
        formatter.setMaximumFractionDigits(2);
    }//from  w  w  w. j a v  a  2  s.c  om

    return result;
}

From source file:Main.java

public static String kgToLBoz(float paramFloat) {
    float f1 = (32768.0F + 23117.0F * paramFloat) / 65536.0F;
    int i = (int) (f1 * 0.1F) / 16;
    float f2 = f1 * 0.1F % 16.0F;
    DecimalFormat localDecimalFormat = new DecimalFormat();
    localDecimalFormat.setMaximumFractionDigits(1);
    localDecimalFormat.setGroupingSize(0);
    localDecimalFormat.setRoundingMode(RoundingMode.FLOOR);
    return i + ":" + localDecimalFormat.format(f2);
}

From source file:Main.java

public static String kgToLB_ForBodyScale(float paramFloat) {
    int i = (int) Math.floor(1.0F + (32768.0F + 144479.0F * (paramFloat * 10.0F)) / 65536.0F);
    if (i % 2 != 0) {
        i--;//from w ww .ja  v  a2 s .c om
    }
    DecimalFormat localDecimalFormat = new DecimalFormat();
    localDecimalFormat.setMaximumFractionDigits(1);
    localDecimalFormat.setGroupingSize(0);
    localDecimalFormat.setRoundingMode(RoundingMode.FLOOR);
    return localDecimalFormat.format(0.1D * i);
}

From source file:Main.java

public static String formatPercentWithFixedFractionDigit(BigDecimal number, int fractionDigit) {
    String result = "0";

    if (number != null) {
        number = number.multiply(new BigDecimal("100"));
        DecimalFormat formatter = new DecimalFormat();
        formatter.setMaximumFractionDigits(fractionDigit);
        formatter.setMinimumFractionDigits(fractionDigit);

        result = formatter.format(number);
    }//from   w  w  w.ja  va  2s . c o m
    return result;
}