字符串元轉分


/**
* 將金額從元轉為分
*
* @param amtY
* String
* @return
*/
public static String formatAmtY2F(String amtY) {
if (amtY == null || "".equals(amtY.trim())|| "0".equals(amtY))
return "0";
if (amtY.indexOf(",") != -1) {
amtY = amtY.replace(",", "");
}

amtY=new DecimalFormat("0.00").format(new BigDecimal(amtY));
int index = amtY.indexOf(".");
int len = amtY.length();
StringBuffer amtF = new StringBuffer();
if (index == -1) {
amtF.append(amtY).append("00");
} else if ((len - index) == 1) {
amtF.append(Long.parseLong(amtY.replace(".", ""))).append("00");
} else if ((len - index) == 2) {
amtF.append(Long.parseLong(amtY.replace(".", ""))).append("0");
} else {
amtF.append(Long.parseLong(amtY.replace(".", "")));
}
return amtF.toString();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM