Update the amount to display precision
equivalent to ~0.01 of the native price
or use most significant decimal
if the updated precision amounts to zero
A simplification of how this is done:
Floor nativePrice into an integer. Take the number of significant digits of the result as x. (significant digits include 0s, and 0 has 1 significant digit)
Round amount to x + 2 decimal places, rounding down, taking the result as r.
If r is not 0 return amount rounded to x + 2 decimal places,
rounding up if roundUp is true and rounding down otherwise
If r is 0, instead return amount truncated (not rounded) to 1 significant digit
Update the amount to display precision equivalent to ~0.01 of the native price or use most significant decimal if the updated precision amounts to zero
A simplification of how this is done:
nativePrice
into an integer. Take the number of significant digits of the result asx
. (significant digits include 0s, and 0 has 1 significant digit)amount
tox + 2
decimal places, rounding down, taking the result asr
.r
is not 0 returnamount
rounded tox + 2
decimal places, rounding up ifroundUp
is true and rounding down otherwiser
is 0, instead returnamount
truncated (not rounded) to 1 significant digitExample