export function _toString(u) { u = u || 0; u = Number(u); return u.toFixed(2); } export function customToLocaleString(amount) { amount = amount || 0; amount = Number(amount); // 将金额转换为字符串 amount = amount.toString(); // 检查是否存在小数点 var decimalIndex = amount.indexOf("."); var decimalPart = ""; if (decimalIndex !== -1) { decimalPart = amount.substring(decimalIndex); amount = amount.substring(0, decimalIndex); } // 添加千分符号 var thousandSeparator = ","; var regex = /(\d+)(\d{3})/; while (regex.test(amount)) { amount = amount.replace(regex, "$1" + thousandSeparator + "$2"); } // 重新组合金额和小数部分 return amount + decimalPart; } // 根据type返回货币符号 export function currencySymbol(type) { if (type == "US") return "$"; else if (type == "HK") return "HK$"; else if (type == "IN") return "₹"; else if (type == "TW") return "NT$"; } // 根据时间戳返回时间 export function gettime(time) { if (!time) { return ""; } var nd = new Date(time); var y = nd.getFullYear(); var mm = nd.getMonth() + 1; var d = nd.getDate(); var h = nd.getHours(); var m = nd.getMinutes(); var c = nd.getSeconds(); if (mm < 10) { mm = "0" + mm; } if (d < 10) { d = "0" + d; } if (h < 10) { h = "0" + h; } if (m < 10) { m = "0" + m; } if (c < 10) { c = "0" + c; } // 17:35:2922-06-2022 return d + "-" + mm + "-" + y + " " + h + ":" + m + ":" + c; } export function _toLocaleString( number, showCurrencySymbol = true, // 是否显示货币符号,默认为 true locale = "en-IN", // 默认使用印度英语的语言环境 options = { // style:可选值为 decimal(小数)、currency(货币)或 percent(百分比); // currency:设置为货币样式时使用的符号,支持列表在这里; // useGrouping:布尔值,是否显示数字分位。 style: "currency", currency: "INR", minimumFractionDigits: 2, //如果不想要显示末尾的小数「.00」,只要设置一下最小分位 minimumFractionDigits 即可(默认是 2): } ) { number = number || 0; number = Math.floor(number * 100) / 100; // 向下取整并保留两位小数 let str = Number(number).toLocaleString(locale, options); if (showCurrencySymbol) { str = str.replace("₹", ""); } return str; }