@exodus/currency
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -0,1 +1,7 @@ | ||
1.0.4 / 2019-06-22 | ||
------------------ | ||
- Add `number-unit.div` | ||
- Use `number-unit.div` in `conversion-by-rate` to avoid using `parseFloat` | ||
1.0.3 / 2019-06-21 | ||
@@ -2,0 +8,0 @@ ------------------ |
@@ -32,4 +32,11 @@ "use strict"; | ||
} else if (ut === ut2) { | ||
rate = parseFloat(rate); | ||
const newUnit = ut1.baseUnit(someNumberUnit._number).mul(ut1[unit1].multiplier).mul(rate === 0 ? 0 : 1 / rate); | ||
let newUnit = ut1.baseUnit(someNumberUnit._number).mul(ut1[unit1].multiplier); | ||
try { | ||
newUnit = newUnit.div(rate); | ||
} catch (err) { | ||
if (String(err.message) !== 'Invalid division by 0') throw err; | ||
newUnit = ut1.baseUnit(0); | ||
} | ||
newUnit._number = newUnit._number.div(ut2[unit2].multiplier); | ||
@@ -36,0 +43,0 @@ return newUnit.to(unit1); |
@@ -217,2 +217,22 @@ "use strict"; | ||
div(num) { | ||
if (_bn.default.isBN(num)) { | ||
return new NumberUnit(this._number.div(num), this.unit); | ||
} | ||
const { | ||
number, | ||
fraction, | ||
fractionLength | ||
} = this._stringToNumberFraction(num, 0); | ||
const fractionPow = new _bn.default(10, 10).pow(new _bn.default(fractionLength, 10)); | ||
const numberBN = new _bn.default(number, 10).imul(fractionPow).iadd(new _bn.default(fraction, 10)); | ||
if (numberBN.isZero()) throw new Error('Invalid division by 0'); | ||
const bn = this._number.mul(fractionPow).div(numberBN); | ||
return new NumberUnit(bn, this.unit); | ||
} | ||
floor() { | ||
@@ -219,0 +239,0 @@ if (this.unit.power === 0) { |
{ | ||
"name": "@exodus/currency", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Currency support.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19863
504