|
|
@@ -155,6 +155,16 @@ export function parsePercent(value = 0, decimal = 2) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 四舍五入,处理计算精度问题
|
|
|
+ * @param value
|
|
|
+ * @param precision
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export function round(value: number, precision = 2) {
|
|
|
+ return Math.round(+(value + 'e' + precision)) / Math.pow(10, precision)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
* 强制保留小数位,不足位数自动补零
|
|
|
* @param value
|
|
|
* @param decimal 保留小数位
|
|
|
@@ -323,18 +333,18 @@ export function sortBy<T extends object, K extends keyof T>(arr: Array<T>, sortV
|
|
|
}
|
|
|
|
|
|
// 身份证号 获取对应的证件年龄
|
|
|
-export function getIdCardAge(cardnum: string) {
|
|
|
+export function getIdCardAge(cardnum: string) {
|
|
|
// 根据身份证号提取出年 月 日
|
|
|
- const idYear = Number(cardnum.substring(6, 10) )
|
|
|
- const idMonth = Number(cardnum.substring(10, 12))
|
|
|
+ const idYear = Number(cardnum.substring(6, 10))
|
|
|
+ const idMonth = Number(cardnum.substring(10, 12))
|
|
|
const idDay = Number(cardnum.substring(12, 14))
|
|
|
// 获取当前日期的年 月 日
|
|
|
- const year = (new Date()).getFullYear()
|
|
|
- const month = (new Date()).getMonth() +1
|
|
|
- const day = (new Date()).getDate()
|
|
|
+ const year = (new Date()).getFullYear()
|
|
|
+ const month = (new Date()).getMonth() + 1
|
|
|
+ const day = (new Date()).getDate()
|
|
|
// 计算年龄
|
|
|
- let age = year - idYear
|
|
|
+ let age = year - idYear
|
|
|
// 需要根据月份和具体日子判断下
|
|
|
- if((idMonth > month) || idMonth == month && idDay > day ){ age-- }
|
|
|
- return age
|
|
|
+ if ((idMonth > month) || idMonth == month && idDay > day) { age-- }
|
|
|
+ return age
|
|
|
}
|