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:
nativePriceinto an integer. Take the number of significant digits of the result asx. (significant digits include 0s, and 0 has 1 significant digit)amounttox + 2decimal places, rounding down, taking the result asr.ris not 0 returnamountrounded tox + 2decimal places, rounding up ifroundUpis true and rounding down otherwiseris 0, instead returnamounttruncated (not rounded) to 1 significant digitExample