7/30 限制前端输入字数
This commit is contained in:
@@ -134,8 +134,8 @@ export function add(a: string | number, b: string | number): number {
|
||||
/**
|
||||
* 乘法 a * b
|
||||
*/
|
||||
export function mul(a: string | number, b: string | number): number {
|
||||
return Number(toBig(a).times(toBig(b)));
|
||||
export function mul(a: string | number, b: string | number, decimal = 2): number {
|
||||
return Number(toBig(a).times(toBig(b)).round(decimal));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,6 +147,50 @@ export function div(a: string | number, b: string | number): number {
|
||||
if (bigB.eq(0)) throw new Error('除数不能为0');
|
||||
return Number(toBig(a).div(bigB));
|
||||
}
|
||||
|
||||
/**
|
||||
* a > b
|
||||
*/
|
||||
export function gtMoney(a: string | number, b: string | number): boolean {
|
||||
return toBig(a).gt(toBig(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* a >= b
|
||||
*/
|
||||
export function gteMoney(a: string | number, b: string | number): boolean {
|
||||
return toBig(a).gte(toBig(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* a < b
|
||||
*/
|
||||
export function ltMoney(a: string | number, b: string | number): boolean {
|
||||
return toBig(a).lt(toBig(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* a <= b
|
||||
*/
|
||||
export function lteMoney(a: string | number, b: string | number): boolean {
|
||||
return toBig(a).lte(toBig(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* a === b 金额相等
|
||||
*/
|
||||
export function eqMoney(a: string | number, b: string | number): boolean {
|
||||
return toBig(a).eq(toBig(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* a !== b 金额不相等
|
||||
*/
|
||||
export function neqMoney(a: string | number, b: string | number): boolean {
|
||||
return !toBig(a).eq(toBig(b));
|
||||
}
|
||||
|
||||
|
||||
// 保留2位小数(金额专用)
|
||||
export function toFixed2(val) {
|
||||
return Number(val).toFixed(2);
|
||||
|
||||
Reference in New Issue
Block a user