Skip to content

Commit

Permalink
fix: issue where negative values like -0.0x were not handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
stmSi committed Jul 25, 2024
1 parent 2d80598 commit 15cad84
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/builtin-ledger-grpc-svc/src/domain/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export function bigintToString(bigintValue: bigint, decimals: number): string {
}
decimals = decimals || 0;

const isNegative = bigintValue < 0n;
let bigintValueToString: string = bigintValue.toString().replace("-", "");

// Get the string corresponding to the bigint and insert a dot according to the decimals.
let bigintValueToString: string = bigintValue.toString();
if (bigintValueToString.length <= decimals) {
bigintValueToString = "0".repeat(decimals - bigintValueToString.length + 1) + bigintValueToString;
}
Expand All @@ -79,5 +81,10 @@ export function bigintToString(bigintValue: bigint, decimals: number): string {
finalString = finalString.slice(0, -1);
}

// Handle negative numbers
if (isNegative) {
finalString = "-" + finalString;
}

return finalString;
}

0 comments on commit 15cad84

Please sign in to comment.