/*
 * @Author: mojunshou 1637302775@qq.com
 * @Date: 2025-04-18 10:57:07
 * @LastEditors: mojunshou 1637302775@qq.com
 * @LastEditTime: 2025-04-28 15:21:30
 * @Description: 工具类
 */

export class Format {
    //格式化微信币，保留2位小数
    static formatWxCoin(wxCoin: number): string {
        //要先除1000
        wxCoin = wxCoin / 1000
        //再保留2位小数
        return wxCoin.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1')
    }

    //格式化红包币，保留两位小数，要除100
    static formatRedPacketCoin(redPacketCoin: number): string {
        //要先除100
        redPacketCoin = redPacketCoin / 100
        //再保留2位小数
        return redPacketCoin.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1')
    }

    //格式化修改的微信币，保留3位小数
    static formatWxCoinModify(wxCoin: number): string {
        //要先除1000
        wxCoin = wxCoin / 1000
        //再保留3位小数
        return wxCoin.toFixed(3).replace(/(\d)(?=(\d{3})+\.)/g, '$1')
    }

    static truncateCustom(str: string, maxLen = 5, suffix = "***"): string {
        return str.length > maxLen
            ? `${str.substring(0, maxLen)}${suffix}`
            : str;
    }
}


