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:Main.java

private static double FormetFileSize(long fileS, int sizeType) {
    DecimalFormat df = new DecimalFormat("#.00");
    double fileSizeLong = 0;
    switch (sizeType) {
    case SIZETYPE_B:
        fileSizeLong = Double.valueOf(df.format((double) fileS));
        break;// w  w w.  j  a  v a  2  s  .c  om
    case SIZETYPE_KB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1024));
        break;
    case SIZETYPE_MB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576));
        break;
    case SIZETYPE_GB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824));
        break;
    default:
        break;
    }

    return fileSizeLong;
}

From source file:com.wuliu.biz.util.WuliuMemberUtil.java

public static WuliuMemberModel convertToWuliuMemberModel(WuliuMemberDO wuliuMemberDO) {
    if (wuliuMemberDO == null) {
        return null;
    }// w  ww  . j ava  2 s.  c  o m

    WuliuMemberModel ret = new WuliuMemberModel();
    ret.setAddress(wuliuMemberDO.getAddress());
    ret.setId(wuliuMemberDO.getId());
    ret.setMobileNumber(wuliuMemberDO.getMobileNumber());
    ret.setName(wuliuMemberDO.getName());
    ret.setNickName(wuliuMemberDO.getNickName());
    ret.setStatus(wuliuMemberDO.getStatus());
    ret.setTelephoneNumber(wuliuMemberDO.getTelephoneNumber());
    ret.setVolumnPrice(wuliuMemberDO.getVolumnPrice());
    ret.setWeightPrice(wuliuMemberDO.getWeightPrice());
    ret.setShopAddress(wuliuMemberDO.getShopAddress());

    DecimalFormat df = new DecimalFormat("0.##");
    if (ret.getWeightPrice() != null) {
        ret.setWeightPriceForDisplay(df.format(ret.getWeightPrice() / 100.0));
    }

    if (ret.getVolumnPrice() != null) {
        ret.setVolumnPriceForDisplay(df.format(ret.getVolumnPrice() / 100.0));
    }

    return ret;
}

From source file:Main.java

public static Double Doubleformat(DecimalFormat df, Double value) {
    if (value == null || value.compareTo(0.0) == 0) {
        return 0.0;
    }/*from   ww  w  .  ja  va2s. c  o m*/
    if (df == null) {
        df = doubleFormat;
    }
    String dfValue = df.format(value);
    dfValue = dfValue.replaceAll("[ ]", "");
    dfValue = dfValue.replaceAll("[,]", "");
    return Double.valueOf(dfValue);
}

From source file:Main.java

/**
 * Format distance to be displayed to the user
 *
 * @param d , distance in metres//w  w  w  . ja v  a  2 s  .co  m
 *
 * @return formatted {@link String}
 */
public static String formatDistance(double d) {
    DecimalFormat formatter = new DecimalFormat("#,### 'm'");
    d = Math.round(d);
    if (d > 1000) {
        formatter = new DecimalFormat("#,###.# 'km'");
        d = d / 1000;
    }

    return formatter.format(d);
}

From source file:com.aliyun.odps.ship.common.Util.java

public static String toReadableNumber(long number) {
    DecimalFormat df = new DecimalFormat("###,###");
    return df.format(number);
}

From source file:Main.java

public static String formetFileSize(long fileS) {
    DecimalFormat df = new DecimalFormat("#.00");
    String fileSizeString = "";
    if (fileS < 1024) {
        fileSizeString = 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 {// ww  w . j a v  a 2s .  com
        fileSizeString = df.format((double) fileS / 1073741824) + " G";
    }
    return fileSizeString;
}

From source file:Main.java

public static String addCommasToStringNumber(String number) {

    double num = 0;
    DecimalFormat formatter;

    try {/* w w  w. java 2 s  .c o  m*/
        num = Double.parseDouble(number);
        formatter = new DecimalFormat("#,###");
    } catch (Exception e) {
        return number;
    }

    return formatter.format(num);
}

From source file:Main.java

public static double getSalesDone(String budget, String Sales) {
    DecimalFormat twoDForm = new DecimalFormat("#.##");

    double bud = Double.parseDouble(budget);
    double sale = Double.parseDouble(Sales);

    double result = (sale / bud) * 100;

    result = Double.valueOf(twoDForm.format(result));
    return result;

}

From source file:com.wuliu.biz.util.WuliuOrderUtil.java

public static WuliuOrderModel convertToWuliuOrderModel(WuliuOrderDO wuliuOrderDO) {
    if (wuliuOrderDO == null) {
        return null;
    }//from   ww w  .  ja  v  a  2s  . c om

    WuliuOrderModel ret = new WuliuOrderModel();
    ret.setCarIndex(wuliuOrderDO.getCarIndex());
    ret.setDaishouFee(wuliuOrderDO.getDaishouFee());
    ret.setId(wuliuOrderDO.getId());
    ret.setJiashouFee(wuliuOrderDO.getJiashouFee());
    ret.setMemberId(wuliuOrderDO.getMemberId());
    ret.setOrderDate(wuliuOrderDO.getOrderDate());
    ret.setOrderNumber(wuliuOrderDO.getOrderNumber());
    ret.setStatus(wuliuOrderDO.getStatus());
    ret.setZhongzhuanFee(wuliuOrderDO.getZhongzhuanFee());
    ret.setComments(wuliuOrderDO.getComments());

    DecimalFormat df = new DecimalFormat("0.##");
    if (ret.getZhongzhuanFee() != null) {
        ret.setZhongzhuanFeeForDisplay(df.format(ret.getZhongzhuanFee() / 100.0));
    }

    if (ret.getDaishouFee() != null) {
        ret.setDaishouFeeForDisplay(df.format(ret.getDaishouFee() / 100.0));
    }

    if (ret.getJiashouFee() != null) {
        ret.setJiashouFeeForDisplay(df.format(ret.getJiashouFee() / 100.0));
    }
    return ret;
}

From source file:Main.java

public static Double getBitmapsize(Bitmap bitmap, int sizeType) {
    long fileS = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        //            fileS = bitmap.getByteCount();
        Bitmap.Config config = bitmap.getConfig();
        if (config == Bitmap.Config.RGB_565 || config == Bitmap.Config.ARGB_4444) {
            fileS = bitmap.getWidth() * bitmap.getHeight() * 2;
        } else if (config == Bitmap.Config.ALPHA_8) {
            fileS = bitmap.getWidth() * bitmap.getHeight();
        } else if (config == Bitmap.Config.ARGB_8888) {
            fileS = bitmap.getWidth() * bitmap.getHeight() * 4;
        }//  w  w  w .  j ava  2s  .  com
    } else {
        fileS = bitmap.getRowBytes() * bitmap.getHeight();// Pre HC-MR1
    }

    DecimalFormat df = new DecimalFormat("#.00");
    double fileSizeLong = 0;
    switch (sizeType) {
    case SIZETYPE_B:
        fileSizeLong = Double.valueOf(df.format((double) fileS));
        break;
    case SIZETYPE_KB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1024));
        break;
    case SIZETYPE_MB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576));
        break;
    case SIZETYPE_GB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824));
        break;
    default:
        break;
    }
    return fileSizeLong;
}