|
@@ -1,6 +1,6 @@
|
|
|
/* eslint-disable no-restricted-globals */
|
|
/* eslint-disable no-restricted-globals */
|
|
|
// 判断传入的是否是数字或者可转为数字的字符串
|
|
// 判断传入的是否是数字或者可转为数字的字符串
|
|
|
-export const isNumber = (value: string | number) => {
|
|
|
|
|
|
|
+export const isNumber = (value: string | number): boolean => {
|
|
|
return /^(-|\+)?\d+(\.\d+)?$/.test(value as string);
|
|
return /^(-|\+)?\d+(\.\d+)?$/.test(value as string);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -23,3 +23,13 @@ export const roundToString = (
|
|
|
const value = roundForObj(obj, decimal);
|
|
const value = roundForObj(obj, decimal);
|
|
|
return value.toFixed(decimal);
|
|
return value.toFixed(decimal);
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+// 取单位前的数字,并转换成整数
|
|
|
|
|
+export const getNumberFromUnit = (unit: string): number => {
|
|
|
|
|
+ const reg = new RegExp('^[0-9]+');
|
|
|
|
|
+ if (unit && reg.test(unit)) {
|
|
|
|
|
+ const arr: any = unit.match(reg);
|
|
|
|
|
+ return parseInt(arr[0], 10);
|
|
|
|
|
+ }
|
|
|
|
|
+ return 1;
|
|
|
|
|
+};
|