Adjust formatting with large balance values (#3871)
This commit is contained in:
parent
583fa4bacd
commit
71f6ec83c1
@ -41,8 +41,16 @@ const DEFAULT_BITLENGTH = BitLengthOption.CHAIN_SPEC as BitLength;
|
||||
function reformat (value: string | BN, isDisabled?: boolean): string {
|
||||
if (isBn(value)) {
|
||||
// format for 4 decimals (align with util)
|
||||
let fmt = (value.mul(BN_TEN_THOUSAND).div(BN_TEN.pow(new BN(formatBalance.getDefaults().decimals))).toNumber() / 10000).toFixed(4);
|
||||
const valStr = value
|
||||
.mul(BN_TEN_THOUSAND)
|
||||
.div(BN_TEN.pow(new BN(formatBalance.getDefaults().decimals)))
|
||||
.toString()
|
||||
.padStart(5, '0'); // 4 after decimal, 1 before, min 5
|
||||
|
||||
// dive using string format (the value may be too large for 2^53-1)
|
||||
let fmt = `${valStr.substr(0, valStr.length - 4)}.${valStr.slice(-4)}`;
|
||||
|
||||
// remove all trailing 0's until the decimal
|
||||
while (fmt.length !== 1 && ['.', '0'].includes(fmt[fmt.length - 1])) {
|
||||
const isLast = fmt.endsWith('.');
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user