SuperDecimal类使用JavsScript中的BigInt(ES2017中的一个新的特性),去解决大数字的计算,以及由于浮点数字的标准数字引起的计算精准度的问题详情可以参考IEEE-754
- SuperDecimal
- new SuperDecimal(numeric)
- .DIVIDE_DECIMAL_PLACE
- .integer :
string - .inteLens :
number - .decimal :
string - .decimalLen :
number - .isNegtive :
boolean - .bigint :
BigInt - .result :
string - .add(addtion) ⇒
SuperDecimal - .sub(substraction) ⇒
SuperDecimal - .mutiply(base) ⇒
SuperDecimal - .divide(divisor) ⇒
SuperDecimal - .pow(n) ⇒
SuperDecimal - .tostr() ⇒
string - .toFixed(decimal) ⇒
string
SuperDecimal类的构造函数
| Param | Type | Description |
|---|---|---|
| numeric | string | number |
数字型的参数 |
用来控制默认的小数点的位数
Kind: instance property of SuperDecimal
整数部分
Kind: instance property of SuperDecimal
Access: public
整数部分字符长度
Kind: instance property of SuperDecimal
Access: public
小数部分
Kind: instance property of SuperDecimal
Access: public
小数部分字符长度
Kind: instance property of SuperDecimal
Access: public
数字的正负性
Kind: instance property of SuperDecimal
Access: public
数字的BigInt的表示
Kind: instance property of SuperDecimal
Access: public
数字的字符形式
Kind: instance property of SuperDecimal
Access: public
superDecimal.add(addtion) ⇒ SuperDecimal
两个数字相加
Kind: instance method of SuperDecimal
| Param | Type | Description |
|---|---|---|
| addtion | SuperDecimal |
加数 |
superDecimal.sub(substraction) ⇒ SuperDecimal
两个数字相减
Kind: instance method of SuperDecimal
| Param | Type | Description |
|---|---|---|
| substraction | SuperDecimal |
减数 |
superDecimal.mutiply(base) ⇒ SuperDecimal
当前SuperDecimal乘以另一个SuperDecimal
Kind: instance method of SuperDecimal
| Param | Type |
|---|---|
| base | SuperDecimal |
superDecimal.divide(divisor) ⇒ SuperDecimal
当前SuperDecimal除以另一个SuperDecimal
Kind: instance method of SuperDecimal
| Param | Type | Description |
|---|---|---|
| divisor | SuperDecimal |
除数 |
superDecimal.pow(n) ⇒ SuperDecimal
计算幂函数,这里为了保障结果的精准性,将会尽可能保证小数的位数
Kind: instance method of SuperDecimal
Returns: SuperDecimal - - 当前数字的幂函数的结果
| Param | Type | Description |
|---|---|---|
| n | number |
当前数字的幂函数 |
把当前的SuperDecimal的数字转化成数字的字符串输出
Kind: instance method of SuperDecimal
以字符的形式输出decimal小数位的字符
Kind: instance method of SuperDecimal
| Param | Type | Default | Description |
|---|---|---|---|
| decimal | number |
10 |
保留小数的位数 |