Package org.stellar.sdk
Class Price
java.lang.Object
org.stellar.sdk.Price
Represents Price. Price in Stellar is represented as a fraction.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic PricefromString(@NonNull String price) Approximatespriceto a fraction.static PriceGenerates a Price SDK object from the XDR representation.intThe denominator of the price fraction.intThe numerator of the price fraction.inthashCode()toString()Returns price as a string.toXdr()Generates Price XDR object.
-
Constructor Details
-
Price
public Price(int numerator, int denominator) Creates a newPriceinstance.- Parameters:
numerator- The numerator of the price fraction.denominator- The denominator of the price fraction.
-
-
Method Details
-
fromString
Approximatespriceto a fraction. Please remember that this function can give unexpected results for values that cannot be represented as a fraction with 32-bit numerator and denominator. It's safer to create a Price object using the constructor.- Parameters:
price- Ex. "1.25"- Returns:
- a new
Priceinstance
-
fromXdr
Generates a Price SDK object from the XDR representation.- Parameters:
price- the XDR Price object- Returns:
- a new
Priceinstance
-
toXdr
Generates Price XDR object.- Returns:
- the XDR representation of this Price
-
toString
Returns price as a string. -
getNumerator
public int getNumerator()The numerator of the price fraction.- Returns:
- the numerator
-
getDenominator
public int getDenominator()The denominator of the price fraction.- Returns:
- the denominator
-
equals
-
hashCode
public int hashCode()
-