fix(Stepper): incorrect value when format minus value (#6238)

This commit is contained in:
neverland
2020-05-07 22:15:46 +08:00
committed by GitHub
parent 3e231f1ab5
commit e61aa29118
5 changed files with 45 additions and 18 deletions
+24
View File
@@ -1,3 +1,27 @@
export function range(num: number, min: number, max: number): number {
return Math.min(Math.max(num, min), max);
}
function trimExtraChar(value: string, char: string, regExp: RegExp) {
const index = value.indexOf(char);
if (index > -1) {
return value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
}
return value;
}
export function formatNumber(value: string, allowDot?: boolean) {
if (allowDot) {
value = trimExtraChar(value, '.', /\./g);
} else {
value = value.split('.')[0];
}
value = trimExtraChar(value, '-', /-/g);
const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g;
return value.replace(regExp, '');
}