JAVA 基础

public class DecimalFormat {

    public static String converCurrencyFormat(BigDecimal currency, int decimalPlace){
        BigDecimal cury = MathUtils.roundHalfUp(currency,decimalPlace);
        String mask = "#,###,##0.";
        for (int i= 0;i < decimalPlace; i++) {
            mask = mask + "0";
        }
        java.text.DecimalFormat format = new java.text.DecimalFormat(mask);
        return format.format(cury);

    }

    public static String converPercentageFormat(BigDecimal percentage, int decimalPlace) {
        String mask = "#,##0.";
        for (int i= 0;i < decimalPlace; i++) {
            mask = mask + "0";
        }
        mask = mask + "%";
        java.text.DecimalFormat format = new java.text.DecimalFormat(mask);
        return format.format(percentage);
    }

}

public class ConvertDateFormat {
//    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    private SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);

    private SimpleDateFormat formatterEn = new SimpleDateFormat("dd MMM, yyyy", Locale.ENGLISH);
    public String convertToDateEn(Date dateStr) throws ParseException{
        String date = formatter.format(dateStr);
        return date;
    }

    public String convertToDate_En(Date dateStr) throws ParseException{
        String date = formatterEn.format(dateStr);
        return date;
    }

    public String convertToDateCn(Date dateStr) throws ParseException{
        ChineseDateFormat chiFormat = new ChineseDateFormat();
        return chiFormat.format(dateStr);
    }
}

你可能感兴趣的:(java)