Skip to content

Commit

Permalink
fix float to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa committed Aug 14, 2024
1 parent b112ed3 commit 3e9ff58
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ecosys/tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export function absBigInt(n) {
export function floatToBigInt(value, decimal) {
const floatStr = value.toString();
if (!floatStr.includes('.')) {
return BigInt(value) * (10n ** decimal);
return BigInt(value) * (10n ** BigInt(decimal));
}

const decimalPlaces = floatStr.split('.')[1].length;
return BigInt(value) * (10n ** (decimal - BigInt(decimalPlaces)))
const fixedValue = BigInt(value * (10 ** decimalPlaces));
return fixedValue * (10n ** (BigInt(decimal) - BigInt(decimalPlaces)))
}

export function pickIndexEndpoint(chain) {
Expand Down

0 comments on commit 3e9ff58

Please sign in to comment.