fix: postage stamp price and TTL calculation (#305)

* fix: postage stamp price and TTL calculation

* chore: removed logs and fixed linter issues
This commit is contained in:
Vojtech Simetka
2022-03-10 17:49:09 +01:00
committed by GitHub
parent d9e7560117
commit d0b3f1abee
3 changed files with 50 additions and 49 deletions
+21
View File
@@ -57,4 +57,25 @@ export class Token {
toFixedDecimal(digits = 7): string {
return this.toDecimal.toFixed(digits)
}
toSignificantDigits(digits = 4): string {
const asString = this.toDecimal.toFixed(16)
let indexOfSignificantDigit = -1
let reachedDecimalPoint = false
for (let i = 0; i < asString.length; i++) {
const char = asString[i]
if (char === '.') {
reachedDecimalPoint = true
indexOfSignificantDigit = i + 1
} else if (reachedDecimalPoint && char !== '0') {
indexOfSignificantDigit = i
break
}
}
return asString.slice(0, indexOfSignificantDigit + digits)
}
}