Merge branch 'dev' into next

This commit is contained in:
chenjiahan
2020-09-06 07:59:45 +08:00
12 changed files with 109 additions and 28 deletions

View File

@@ -16,14 +16,22 @@ function trimExtraChar(value: string, char: string, regExp: RegExp) {
return value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
}
export function formatNumber(value: string, allowDot?: boolean) {
export function formatNumber(
value: string,
allowDot = true,
allowMinus = true
) {
if (allowDot) {
value = trimExtraChar(value, '.', /\./g);
} else {
value = value.split('.')[0];
}
value = trimExtraChar(value, '-', /-/g);
if (allowMinus) {
value = trimExtraChar(value, '-', /-/g);
} else {
value = value.replace(/-/, '');
}
const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g;