Module org.firebirdsql.jaybird
Package org.firebirdsql.extern.decimal

# Class Decimal<T extends Decimal<T>>

java.lang.Object
org.firebirdsql.extern.decimal.Decimal<T>

Direct Known Subclasses:
  `Decimal128`, `Decimal32`, `Decimal64`

public abstract class Decimal<T extends Decimal<T>> extends Object
Abstract base class for IEEE-754 decimals.

Author:
  Mark Rotteveel

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final double`
  `doubleValue()`
  Converts this decimal to a double value.
  `final boolean`
  `equals(Object o)`
  `final int`
  `hashCode()`
  `final BigDecimal`
  `toBigDecimal()`
  Converts this decimal to a `BigDecimal`.
  `final byte[]`
  `toBytes()`
  Converts this decimal to its IEEE-754 byte encoding in network byte-order (aka big-endian).
  `final <D extends Decimal<D>>
  D`
  `toDecimal(Class<D> decimalType)`
  Converts this decimal to the requested decimal type, rounding when necessary.
  `final <D extends Decimal<D>>
  D`
  `toDecimal(Class<D> decimalType, OverflowHandling overflowHandling)`
  Converts this decimal to the requested decimal type, rounding when necessary.
  `final String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### toBigDecimal

    public final BigDecimal toBigDecimal()
    Converts this decimal to a `BigDecimal`.
    Returns:
      Value as BigDecimal
    Throws:
      `DecimalInconvertibleException` - If this value is a NaN, sNaN or Infinity, which can't be represented as a `BigDecimal`.

  - ### doubleValue

    public final double doubleValue()
    Converts this decimal to a double value.

    For normal, finite, decimal values, see `BigDecimal.doubleValue()`.

    For type INFINITY, returns `Double.POSITIVE_INFINITY` or `Double.NEGATIVE_INFINITY`. For all NaN-specials, returns `Double.NaN` (irrespective of signum).

    Returns:
      this decimal converted to a `double`

  - ### toBytes

    public final byte[] toBytes()
    Converts this decimal to its IEEE-754 byte encoding in network byte-order (aka big-endian).

    This method returns network byte-order (aka big-endian). When you need little-endian order, you will need to reverse the bytes in the array.

    Returns:
      byte array

  - ### toDecimal

    public final <D extends Decimal<D>> D toDecimal(Class<D> decimalType)
    Converts this decimal to the requested decimal type, rounding when necessary.
    Type Parameters:
      `D` - Type parameter of decimal
    Parameters:
      `decimalType` - Target decimal type
    Returns:
      This value after conversion, or this if `decimalType` is the same as this type
    Throws:
      `IllegalArgumentException` - If conversion to `decimalType` is not supported

  - ### toDecimal

    public final <D extends Decimal<D>> D toDecimal(Class<D> decimalType, OverflowHandling overflowHandling)
    Converts this decimal to the requested decimal type, rounding when necessary.
    Type Parameters:
      `D` - Type parameter of decimal
    Parameters:
      `decimalType` - Target decimal type
      `overflowHandling` - Handling of overflows
    Returns:
      This value after conversion, or this if `decimalType` is the same as this type
    Throws:
      `IllegalArgumentException` - If conversion to `decimalType` is not supported
      `DecimalOverflowException` - If `OverflowHandling#THROW_EXCEPTION` and the value is out of range for the target decimal type.

  - ### toString

    public final String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public final boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public final int hashCode()
    Overrides:
      `hashCode` in class `Object`