Class Price

java.lang.Object
org.stellar.sdk.Price

public final class Price extends Object
Represents Price. Price in Stellar is represented as a fraction.
  • Constructor Details

    • Price

      public Price(int numerator, int denominator)
      Creates a new Price instance.
      Parameters:
      numerator - The numerator of the price fraction.
      denominator - The denominator of the price fraction.
  • Method Details

    • fromString

      public static Price fromString(@NonNull @NonNull String price)
      Approximates price to 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 Price instance
    • fromXdr

      public static Price fromXdr(Price price)
      Generates a Price SDK object from the XDR representation.
      Parameters:
      price - the XDR Price object
      Returns:
      a new Price instance
    • toXdr

      public Price toXdr()
      Generates Price XDR object.
      Returns:
      the XDR representation of this Price
    • toString

      public String toString()
      Returns price as a string.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this Price
    • 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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object