/**
* 功能描述:金额字符串转换:单位元转成单分
* @param o 传入需要转换的金额字符串
* @return 转换后的金额字符串
*/
public static String yuanToFen(Object o) {
if (o == null)
return "0";
String s = o.toString();
int posIndex = -1;
String str = "";
StringBuilder sb = new StringBuilder();
if (s != null && s.trim().length() > 0 && !s.equalsIgnoreCase("null")) {
posIndex = s.indexOf(".");
if (posIndex > 0) {
int len = s.length();
if (len == posIndex + 1) {
str = s.substring(0, posIndex);
if (str == "0") {
str = "";
}
sb.append(str).append("00");
} else if (len == posIndex + 2) {
str = s.substring(0, posIndex);
if (str == "0") {
str = "";
}
sb.append(str).append(s.substring(posIndex + 1, posIndex + 2)).append("0");
} else if (len == posIndex + 3) {
str = s.substring(0, posIndex);
if (str == "0") {
str = "";
}
sb.append(str).append(s.substring(posIndex + 1, posIndex + 3));
} else {
str = s.substring(0, posIndex);
if (str == "0") {
str = "";
}
sb.append(str).append(s.substring(posIndex + 1, posIndex + 3));
}
} else {
sb.append(s).append("00");
}
} else {
sb.append("0");
}
str = removeZero(sb.toString());
if (str != null && str.trim().length() > 0 && !str.trim().equalsIgnoreCase("null")) {
return str;
} else {
return "0";
}
}
元转分金额字符串转换:单位元转成单分
最新推荐文章于 2022-11-07 12:32:22 发布