金额转换工具类:把元转换成分(1元=100)
该方法用来把 元转换成分(1元=100)
代码如下:
点击查看代码
/**
* @Classname AmoutUtils
* @Description 金额转换工具类:把元转换成分(1元=100)
* @Date 2022/3/25 16:53
* @Created by 小郭
*/
public class AmountUtils {
public static String getMoney(String amount) {
if (amount == null) {
return "";
}
//金额转化为分为单位
//处理包含:¥、$的金额
String currency = amount.replaceAll("\\$|\\¥|\\,", "");
int index = currency.indexOf(".");
int length = currency.length();
Long amLong = 0L;
if (index == -1) {
amLong = Long.valueOf(currency + "00");
} else if (length - index >= 3) {
amLong = Long.valueOf((currency.substring(0, index + 3)).replace(".", ""));
} else if (length - index == 2) {
amLong = Long.valueOf((currency.substring(0, index + 2)).replace(".", "") + 0);
} else {
amLong = Long.valueOf((currency.substring(0, index + 1)).replace(".", "") + "00");
}
return amLong.toString();
}
}
本文来自博客园,作者:青喺半掩眉砂,转载请注明原文链接:https://www.cnblogs.com/xiaoguo-java/p/16057886.html