StellarAmount
in package
Represents an amount in the Stellar network with proper precision handling
Stellar amounts are represented internally as 64-bit signed integers in stroops, where 1 XLM = 10,000,000 stroops. This class handles conversion between decimal amounts and stroops while ensuring proper precision and validation.
Maximum supported amount: 922337203685.4775807 XLM (9223372036854775807 stroops)
Example usage:
// Create from decimal string
$amount = StellarAmount::fromString("100.50");
// Create from float
$amount = StellarAmount::fromFloat(100.5);
// Get decimal representation
$decimal = $amount->getDecimalValueAsString(); // "100.5000000"
// Get stroops value
$stroops = $amount->getStroopsAsString(); // "1005000000"
Tags
Table of Contents
Properties
- $maxSignedStroops64 : BigInteger
- $stroops : BigInteger
- $stroopScaleBignum : BigInteger
Methods
- __construct() : mixed
- StellarAmount constructor
- fromFloat() : StellarAmount
- Creates a StellarAmount from a floating point number
- fromString() : StellarAmount
- Creates a StellarAmount from a decimal string
- fromXdr() : StellarAmount
- Reads a StellarAmount from a SIGNED 64-bit integer
- getDecimalValueAsString() : string
- Returns the decimal value as a string with 7 decimal places
- getStroops() : BigInteger
- Returns the raw value in stroops
- getStroopsAsString() : string
- Returns the raw value in stroops as a string
- maximum() : StellarAmount
- Returns the maximum supported amount
Properties
$maxSignedStroops64
protected
BigInteger
$maxSignedStroops64
Maximum value that fits in a signed 64-bit integer (9223372036854775807)
$stroops
protected
BigInteger
$stroops
The amount value in stroops
$stroopScaleBignum
protected
BigInteger
$stroopScaleBignum
Scale factor for stroop conversion (10,000,000)
Methods
__construct()
StellarAmount constructor
public
__construct(BigInteger $stroops) : mixed
Parameters
- $stroops : BigInteger
-
The amount in stroops (1 XLM = 10,000,000 stroops)
Tags
fromFloat()
Creates a StellarAmount from a floating point number
public
static fromFloat(float $amount) : StellarAmount
Parameters
- $amount : float
-
The amount as a decimal number (e.g., 100.5 for 100.5 XLM)
Tags
Return values
StellarAmount —The amount object
fromString()
Creates a StellarAmount from a decimal string
public
static fromString(string $decimalAmount) : StellarAmount
Surrounding whitespace and any space are removed, and a comma is rejected, because a comma separates groups in some locales and decimals in others. What remains must be digits with at most one decimal point and at most one leading sign. An asset carries seven decimal places, so a finer amount is rejected rather than rounded; trailing zeroes do not count towards that limit, and "0.50000000" is accepted as 0.5.
Parameters
- $decimalAmount : string
-
The amount as a string (e.g., "100.5" or "1000.25")
Tags
Return values
StellarAmount —The amount object
fromXdr()
Reads a StellarAmount from a SIGNED 64-bit integer
public
static fromXdr(XdrBuffer $xdr) : StellarAmount
Parameters
- $xdr : XdrBuffer
-
The XDR buffer to read from
Tags
Return values
StellarAmount —The decoded amount
getDecimalValueAsString()
Returns the decimal value as a string with 7 decimal places
public
getDecimalValueAsString() : string
Return values
string —The amount formatted as a decimal string (e.g., "100.5000000")
getStroops()
Returns the raw value in stroops
public
getStroops() : BigInteger
Return values
BigInteger —The amount in stroops as a BigInteger object
getStroopsAsString()
Returns the raw value in stroops as a string
public
getStroopsAsString() : string
Return values
string —The amount in stroops as a numeric string
maximum()
Returns the maximum supported amount
public
static maximum() : StellarAmount
Tags
Return values
StellarAmount —The maximum amount (922337203685.4775807 XLM)