1,String类型的数据

/** 
 * @param strValue 待处理的数 
 * @param num 隔的位数 
 */  
public static String separateStr(String strValue, int num) {
    StringBuilder sb = new StringBuilder();// 创建一个空的StringBuilder对象
    sb.append(strValue); // 追加字符串

    int length = strValue.length();
    for(int i = length - num ; i > 0; i -= num) {
        sb.insert(i ,',');
    }
    
    strValue = sb.toString();// 将StringBuilder对象转换为String对象并输出
    return strValue;
}

2,Double类型的数据

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
public static String separateDouble(Double doubleValue) {
    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.CHINA);
    String str = currencyFormat.format(doubleValue);    
    return str;
}  

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄