Compare commits
2 Commits
92311e0aaf
...
63a9a1def5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63a9a1def5 | ||
|
|
a0ddac37f5 |
@@ -22,19 +22,19 @@ export function maskIdNumber() {
|
||||
* 金额格式化
|
||||
* num 金额
|
||||
* decimals 保留几位小数,默认2位
|
||||
* units 默认 units ¥
|
||||
* units 默认 units ¥
|
||||
*/
|
||||
export function formatMoney(num, decimals,units){
|
||||
units = units || '¥ '
|
||||
|
||||
num = parseFloat(num/100);
|
||||
if (isNaN(num)) return units+0;
|
||||
|
||||
|
||||
decimals = typeof decimals === 'undefined' ? 2 : decimals;
|
||||
|
||||
|
||||
var parts = num.toFixed(decimals).split('.');
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
|
||||
|
||||
let retVal = 0;
|
||||
// let part1 = parts[1]
|
||||
// if(parseInt(part1)==0){
|
||||
@@ -44,4 +44,24 @@ export function formatMoney(num, decimals,units){
|
||||
// }
|
||||
|
||||
return units+retVal;
|
||||
}
|
||||
}
|
||||
|
||||
export function dateFormat(fmt, date) {
|
||||
let ret;
|
||||
const opt = {
|
||||
"Y+": date.getFullYear().toString(), // 年
|
||||
"m+": (date.getMonth() + 1).toString(), // 月
|
||||
"d+": date.getDate().toString(), // 日
|
||||
"H+": date.getHours().toString(), // 时
|
||||
"M+": date.getMinutes().toString(), // 分
|
||||
"S+": date.getSeconds().toString() // 秒
|
||||
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
||||
};
|
||||
for (let k in opt) {
|
||||
ret = new RegExp("(" + k + ")").exec(fmt);
|
||||
if (ret) {
|
||||
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
|
||||
};
|
||||
};
|
||||
return fmt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user