OfferPriceResponse
in package
Rational representation of offer price as a fraction
This response represents an offer price as a rational number using numerator (n) and denominator (d) components. This precise fractional representation avoids floating-point rounding errors and maintains exact price ratios as stored on the Stellar ledger.
The price represents the ratio of buying asset units to selling asset units. For example, if n=3 and d=2, the price is 1.5 buying units per selling unit. This format matches the Price XDR structure used in Stellar protocol operations.
Companion to the decimal string price field in OfferResponse for applications requiring exact arithmetic.
Tags
Table of Contents
Methods
- fromJson() : OfferPriceResponse
- Creates an OfferPriceResponse from JSON data
- getD() : int
- Gets the denominator of the price fraction
- getN() : int
- Gets the numerator of the price fraction
- loadFromJson() : void
Methods
fromJson()
Creates an OfferPriceResponse from JSON data
public
static fromJson(array<string|int, mixed> $json) : OfferPriceResponse
Parameters
- $json : array<string|int, mixed>
-
Associative array of parsed JSON response
Return values
OfferPriceResponse —The populated price response
getD()
Gets the denominator of the price fraction
public
getD() : int
Return values
int —The denominator (d) value
getN()
Gets the numerator of the price fraction
public
getN() : int
Return values
int —The numerator (n) value
loadFromJson()
protected
loadFromJson(array<string|int, mixed> $json) : void
Parameters
- $json : array<string|int, mixed>