DecimalString. A number appears only inside display math. This page describes the contract, the three tiers of numeric helpers, and the verbs that name them.
The DecimalString contract
Every monetary or quantity value that crosses a package, provider, or network boundary is a DecimalString from @lifi/perps-types. It matches DECIMAL_PATTERN: an optional leading -, digits, and an optional . with digits. It has no grouping, exponent, currency sign, or whitespace.
isDecimalString(value)tests a value against the pattern.truncateDecimal,decimalToBaseUnits, and the account-sidewire/helpers throwPerpsErrorwithValidationErrorfor a string that fails the pattern.calculateOrderAmountsgivesnullfor one.baseUnitsToDecimalthrowsPerpsErrorwithValidationErrorfor an amount that is not an integer string, such as'1.5'or'1e3'.- No exported signature carries a
Big. The SDK and the providers compute withbig.jsinternally, and give back aDecimalStringor anumber. - A
numberis for display math and small integers only, such as leverage, decimals, percentages, and chart values. Anumbernever goes to a venue. - A producer that builds a
DecimalStringfrom anumberwrites plain notation, never exponent notation.numberToDecimalStringdoes this.
Three tiers
The numeric helpers sit in three tiers. Each tier has one input type, one output type, and one rule.
A value for a venue comes from
wire/ or from a provider field. A value for a screen goes through parseDecimal, then math/, then format*.
Vocabulary
One verb names one kind of transformation.
No function in
decimal/, math/, or wire/ uses a derive, predict, or convert verb, or a bare noun as its name.
See Utilities for the signature and an example of each helper.