package com.nuvole.poscom.util;
|
|
import java.math.BigDecimal;
|
|
/**
|
* @Description 语音内容格式化
|
* @Author ZHAOXL
|
* @Date 2024/3/7 13:15
|
* @Version 1.0
|
*/
|
public class PoscomVoice {
|
|
/**
|
* 支付宝
|
*/
|
public final static String ZFB = "2007";
|
/**
|
* 微信
|
*/
|
public final static String WX = "2008";
|
|
/**
|
* 云闪付
|
*/
|
public final static String YSF = "2011";
|
|
/**
|
* 现金
|
*/
|
public final static String XJ = "2014";
|
|
/**
|
* 语音类型。
|
* 2 不自动播放新订单,真人语音
|
*/
|
public final static String VOICE_TYPE_2 = "2";
|
|
/**
|
* 语音中部内容
|
*/
|
public final static String VOICE_MIDDLE = "已收款";
|
|
/**
|
* 分隔符
|
*/
|
public final static String SPLIT = "|";
|
|
private final static String unit[][] = {{"", "万", "亿"}, {"", "十", "百", "千"}};
|
|
/**
|
* 格式化语音字符串
|
* @param strs 参数
|
* @return String
|
* @Author ZHAOXL
|
* @Date 2024/3/7 13:57
|
* @Version 1.0
|
*/
|
public static String format(String strs) {
|
StringBuilder sb=new StringBuilder();
|
for (char c : strs.toCharArray()) {
|
sb.append(c);
|
sb.append(SPLIT);
|
}
|
return sb.toString();
|
}
|
|
/**
|
* 格式化金额
|
* @param price 金额
|
* @return String
|
* @Author ZHAOXL
|
* @Date 2024/3/7 16:07
|
* @Version 1.0
|
*/
|
public static String priceFormat(Long price) {
|
BigDecimal decimal = new BigDecimal("" + price).divide(new BigDecimal("100"));
|
Double n = decimal.doubleValue();
|
StringBuilder sb = new StringBuilder();
|
String numStr = String.valueOf(n);
|
int dotIndex = numStr.indexOf(".");
|
String decimalPart = numStr.substring(dotIndex);
|
if (".0".equals(decimalPart)) {
|
decimalPart = "";
|
}
|
int integerPart = (int) Math.floor(n);
|
if (integerPart == 0) {
|
sb.append("0");
|
};
|
for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
|
sb.insert(0, unit[0][i]);
|
for (int j = 0; j < unit[1].length && n > 0; j++) {
|
if (integerPart % 10 > 0) {
|
sb.insert(0, integerPart % 10 + unit[1][j]);
|
}
|
integerPart = integerPart / 10;
|
}
|
}
|
sb.append(decimalPart + "元");
|
return sb.toString();
|
}
|
}
|