标签:io os ar for div 2014 on log ad
private static Logger logger = Logger.getLogger(DateUtils.class);
public final static BigDecimal SYS_MULTIPLE = new BigDecimal(100);
public final static BigDecimal RATE_MULTIPLE = new BigDecimal(10000);
/**
* 字串轉BotCashier系統數值
* @param amtStr*100
* @return
*/
public static int strToSysInt(String amtStr){
if (amtStr == null) return 0;
try{
amtStr=amtStr.replace(",", "");
BigDecimal amount = new BigDecimal(amtStr);
return amount.multiply(SYS_MULTIPLE).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}catch (Exception e){
logger.error("[AmtUtils convert amt string error]", e);
return 0;
}
}
/**
* BotCashier系統數字值轉成字串
* @param amt
* @return
*/
public static Integer sysIntToStr(Integer amt){
if (amt == null) return 0;
try{
//BigDecimal amount = new BigDecimal(amt);
//return amount.divide(SYS_MULTIPLE, 0, BigDecimal.ROUND_HALF_UP);
return amt/100;
}catch (Exception e){
logger.error("[AmtUtils convert amt error]", e);
return 0;
}
}
/**
* 系統數值字串轉數值
* @param amtStr/100
* @return
*/
public static int SysStrToInt(String amtStr){
if (amtStr == null) return 0;
try{
BigDecimal amount = new BigDecimal(amtStr);
return amount.divide(SYS_MULTIPLE, 2, BigDecimal.ROUND_HALF_UP).intValue();
}catch (Exception e){
logger.error("[AmtUtils convert amt string error]", e);
return 0;
}
}
//——————————————————————————————————Hellian Added 格式化金額 2014.7.15—————————————————————————————————
/**
* 將字符串金額格式化
* @param amtStr
* @return
*/
public static String amtStrFomat(String amtStr){
if (amtStr == null || amtStr.equals("null")) return "0";
try{
DecimalFormat dFormat=new DecimalFormat("###,##0.00");
return dFormat.format(Integer.parseInt(amtStr));
}catch (Exception e){
logger.error("[AmtUtils convert amt string error]", e);
return "0";
}
}
/**
* 將整型金額格式化
* @param amt
* @return
*/
public static String amtFomat(Integer amt){
if (amt == null) return "0";
try{
DecimalFormat dFormat=new DecimalFormat("###,##0.00");
return dFormat.format(amt);
}catch (Exception e){
logger.error("[AmtUtils convert amt string error]", e);
return "0";
}
}
//————————————————————————————————————————————————————————————————————————————————————————————————————
/**
* 計算信用卡手續費 產生實際字串
* @param amt 交易金額(為系統數字)
* @param cardRate 費率(為系統數字)
* ex: amt=10000(實際金額為100), rate=200(實際費率為0.02)
* @return
*/
public static Integer calculateCardFeeStr(Integer amt, Integer cardRate){
try{
return sysIntToStr(calculateCardFee(amt, cardRate));
}catch (Exception e){
logger.error("[AmtUtils calculate amt error]", e);
return 0;
}
}
/**
* 計算信用卡手續費 產生系統數字
* @param amt 交易金額(為系統數字)
* @param cardRate 費率(為系統數字)
* ex: amt=10000(實際金額為100), rate=200(實際費率為0.02)
* @return
*/
public static int calculateCardFee(Integer amt, Integer cardRate){
try{
BigDecimal amount = new BigDecimal(amt);
BigDecimal rate = new BigDecimal(cardRate).divide(RATE_MULTIPLE);
return amount.multiply(rate).setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
}catch (Exception e){
logger.error("[AmtUtils calculate amt error]", e);
return 0;
}
}
public static void main(String[] args) {
System.out.println(calculateCardFee(10000, strToSysInt("2.5")));
System.out.println(calculateCardFeeStr(10000, strToSysInt("2.5")));
}
标签:io os ar for div 2014 on log ad
原文地址:http://www.cnblogs.com/xiaohaizhuimeng/p/4043490.html