fix too aggressively flooring BN math (#277)
* fix too aggressively flooring BN math * use i80f48 for division Co-authored-by: Maximilian Schneider <mail@maximilianschneider.net>
This commit is contained in:
parent
cc220f56e3
commit
73792dd6ea
|
@ -34,9 +34,11 @@ export function toUiDecimals(
|
|||
nativeAmount: BN | I80F48 | number,
|
||||
decimals: number,
|
||||
): number {
|
||||
// TODO: remove BN and upgrade to bigint https://github.com/solana-labs/solana/issues/27440
|
||||
if (nativeAmount instanceof BN) {
|
||||
return nativeAmount.div(new BN(Math.pow(10, decimals))).toNumber();
|
||||
} else if (nativeAmount instanceof I80F48) {
|
||||
nativeAmount = I80F48.fromU64(nativeAmount);
|
||||
}
|
||||
if (nativeAmount instanceof I80F48) {
|
||||
return nativeAmount
|
||||
.div(I80F48.fromNumber(Math.pow(10, decimals)))
|
||||
.toNumber();
|
||||
|
|
Loading…
Reference in New Issue