Class Price

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

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

    Constructors
    Constructor
    Description
    Price(int n, int d)
    Create a new price.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    static Price
    fromString(@NonNull String price)
    Approximates price to a fraction.
    static Price
    fromXdr(org.stellar.sdk.xdr.Price price)
    Generates a Price SDK object from the XDR representation.
    int
    Returns denominator
    int
    Returns numerator.
    int
     
    Returns price as a string.
    org.stellar.sdk.xdr.Price
    Generates Price XDR object.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Price

      public Price(int n, int d)
      Create a new price. Price in Stellar is represented as a fraction.
      Parameters:
      n - numerator
      d - denominator
  • Method Details

    • getNumerator

      public int getNumerator()
      Returns numerator.
    • getDenominator

      public int getDenominator()
      Returns denominator
    • 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"
    • fromXdr

      public static Price fromXdr(org.stellar.sdk.xdr.Price price)
      Generates a Price SDK object from the XDR representation.
    • toXdr

      public org.stellar.sdk.xdr.Price toXdr()
      Generates Price XDR object.
    • toString

      public String toString()
      Returns price as a string.
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object