Example usage for java.text DecimalFormat format

List of usage examples for java.text DecimalFormat format

Introduction

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

Prototype

public final String format(double number) 

Source Link

Document

Specialization of format.

Usage

From source file:com.squarespace.template.plugins.platform.PlatformUtils.java

public static String formatPercentage(double percentage, boolean trim, Locale locale) {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    String pattern = trim ? "#,##0.###" : "#,##0.00#";
    DecimalFormat format = new DecimalFormat(pattern, symbols);
    return format.format(percentage);
}

From source file:jp.co.opentone.bsol.framework.core.util.ConvertUtil.java

/**
 * 3???./*from   ww w. j  a  v a2s  . c om*/
 * @param value 
 * @return 3?
 */
public static String formatNumber(Integer value) {
    DecimalFormat f = new DecimalFormat("#,##0");
    return value == null ? "" : f.format(value).toString();
}

From source file:Main.java

public static String FormetFileSize(long fileS) {
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileS < 1024) {
        fileSizeString = df.format((double) fileS) + "B";
    } else if (fileS < 1048576) {
        fileSizeString = df.format((double) fileS / 1024) + "K";
    } else if (fileS < 1073741824) {
        fileSizeString = df.format((double) fileS / 1048576) + "M";
    } else {/*from w  w w.  j  a va  2s.c om*/
        fileSizeString = df.format((double) fileS / 1073741824) + "G";
    }
    return fileSizeString;
}

From source file:Main.java

public static String formatCurrp(float f) {
    DecimalFormat df = new DecimalFormat("#0.00");
    String currSym = userInfo[5];
    if (userInfo[6].equals("false")) {
        return df.format(f) + currSym;
    } else {//  w  w  w. j a  va2  s  .co  m
        return currSym + df.format(f);
    }
}

From source file:Main.java

public static String changeMoney(String pattern, String value) {
    double va = 0;
    try {//  w  ww . j  av  a  2  s  .  co m
        va = Double.parseDouble(value);
    } catch (Exception e) {
        return "";
    }
    DecimalFormat myFormatter = new DecimalFormat(pattern);
    myFormatter.applyPattern(pattern);
    return myFormatter.format(va);
}

From source file:Main.java

public static String FormetFileSize(long fileSize) {
    DecimalFormat df = new DecimalFormat("0.0");
    String fileSizeString = "";
    if (fileSize < 1024L)
        fileSizeString = df.format(fileSize) + "B";
    else if (fileSize < 1048576L)
        fileSizeString = df.format(fileSize / 1024.0D) + "K";
    else if (fileSize < 1073741824L)
        fileSizeString = df.format(fileSize / 1048576.0D) + "M";
    else {/*from   w w w.j a  va2 s .  c o m*/
        fileSizeString = df.format(fileSize / 1073741824.0D) + "G";
    }
    return fileSizeString;
}

From source file:Main.java

public static String formatFileSizeToString(long fileLen) {
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileLen < 1024) {
        fileSizeString = df.format((double) fileLen) + "B";
    } else if (fileLen < 1048576) {
        fileSizeString = df.format((double) fileLen / 1024) + "K";
    } else if (fileLen < 1073741824) {
        fileSizeString = df.format((double) fileLen / 1048576) + "M";
    } else {//  w  w  w  .  j av  a2 s.  co m
        fileSizeString = df.format((double) fileLen / 1073741824) + "G";
    }
    return fileSizeString;
}

From source file:Main.java

public static String getFriendlyFileSize(long fileSize) {
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileSize < 1024) {
        fileSizeString = df.format((double) fileSize) + "B";
    } else if (fileSize < 1048576) {
        fileSizeString = df.format((double) fileSize / 1024) + "KB";
    } else if (fileSize < 1073741824) {
        fileSizeString = df.format((double) fileSize / 1048576) + "MB";
    } else {//from  ww w  .ja  v a 2  s  .  c om
        fileSizeString = df.format((double) fileSize / 1073741824) + "GB";
    }
    return fileSizeString;
}

From source file:Main.java

public static String formatCurr(float f) {
    DecimalFormat df = new DecimalFormat("#0.00");
    int currSym = userInfo[5].charAt(0);
    if (userInfo[6].equals("false")) {
        return df.format(f) + "&#" + currSym + ";";
    } else {/*from   w w  w  .  j  a  v  a  2 s  .co  m*/
        return "&#" + currSym + ";" + df.format(f);
    }
}

From source file:Main.java

protected static final String encodingUTF8andSignPrefix(byte[] src, int srart, int length) throws Exception {
    byte[] b = new String(src, srart, length, "euc-kr").getBytes("utf-8");
    String str = new String(b).trim();
    str = str.substring(searchChar(str));
    DecimalFormat f = new DecimalFormat("###,###,###");
    f.setPositivePrefix("+");
    f.setNegativePrefix("-");
    return f.format(Double.parseDouble(str));
}