mirror of
https://github.com/youzan/vant.git
synced 2026-03-18 03:00:26 +08:00
Merge branch 'dev' into next
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user