Function updatePrecisionToDisplay

  • 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:

    1. 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)
    2. Round amount to x + 2 decimal places, rounding down, taking the result as r.
    3. If r is not 0 return amount rounded to x + 2 decimal places, rounding up if roundUp is true and rounding down otherwise
    4. If r is 0, instead return amount truncated (not rounded) to 1 significant digit

    Example

    updatePrecisionToDisplay(0.000357, 0.1) // '0.0003'
    updatePrecisionToDisplay(0.000357, 10) // '0.0003'
    updatePrecisionToDisplay(0.000357, 100) // '0.00035'
    updatePrecisionToDisplay(0.000357, 1000) // '0.000357'

    updatePrecisionToDisplay(0.000357, 100, true) // '0.00036'

    Parameters

    • amount: Value
    • nativePrice: Value
    • roundUp: boolean = false

    Returns string

Generated using TypeDoc