SepRequestAmount
in package
Renders an asset amount for a SEP request field.
Scoped to the classic seven decimal places, and to request fields the SDK types as a float. Not for Soroban token amounts, whose scale the token defines and which routinely carry far more than seven decimals, and not for transaction amounts, which reach operation XDR through AbstractOperation::toXdrAmount.
Table of Contents
Methods
- format() : string
- Renders an amount as a plain decimal string suitable for a request parameter.
Methods
format()
Renders an amount as a plain decimal string suitable for a request parameter.
public
static format(float $amount) : string
The rendering starts from the shortest decimal representation that reads back to the same float and rounds it to at most seven decimal places, trimming trailing fractional zeroes and suppressing the decimal point for whole amounts. It never uses scientific notation, which anchors do not accept, and it never renders the binary expansion behind the shortest representation. A fraction that ends exactly halfway rounds away from zero.
The rendering is locale independent: every step is decimal string arithmetic on json_encode's output, which always uses ASCII digits and a period whatever LC_NUMERIC a caller's setlocale() run has applied. The serialize_precision setting is pinned to -1 for the encode and restored, so a host configuration that caps or widens it cannot change the digits.
Two limits are worth knowing. An amount below half a stroop rounds to 0 and the sign is dropped, and a non-finite amount renders as the empty string; neither names an amount the caller can transact, and both leave the anchor to answer.
Parameters
- $amount : float
-
The amount to render.
Return values
string —The amount as a plain decimal string.