lijuncheng
10 months ago
5 changed files with 28 additions and 4 deletions
@ -0,0 +1,17 @@ |
|||
/* 解决js计算精度问题 */ |
|||
import { Decimal } from 'decimal.js';//引入
|
|||
class Calc { |
|||
add(num1,num2) { |
|||
return new Decimal(num1).add(new Decimal(num2)) |
|||
} |
|||
sub(num1,num2) { |
|||
return new Decimal(num1).sub(new Decimal(num2)) |
|||
} |
|||
mul(num1,num2) { |
|||
return new Decimal(num1).mul(new Decimal(num2)) |
|||
} |
|||
div(num1,num2) { |
|||
return new Decimal(num1).div(new Decimal(num2)) |
|||
} |
|||
} |
|||
export const calc = new Calc(); |
Loading…
Reference in new issue