@Public public final class Decimal extends Object implements Comparable<Decimal>, Serializable
DecimalType
.
This data structure is immutable and might store decimal values in a compact representation (as a long value) if values are small enough.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Decimal that) |
Decimal |
copy()
Returns a copy of this
Decimal object. |
boolean |
equals(Object o) |
static Decimal |
fromBigDecimal(BigDecimal bd,
int precision,
int scale)
Creates an instance of
Decimal from a BigDecimal and the given precision and
scale. |
static Decimal |
fromUnscaledBytes(byte[] unscaledBytes,
int precision,
int scale)
Creates an instance of
Decimal from an unscaled byte array value and the given
precision and scale. |
static Decimal |
fromUnscaledLong(long unscaledLong,
int precision,
int scale)
Creates an instance of
Decimal from an unscaled long value and the given precision
and scale. |
int |
hashCode() |
boolean |
isCompact()
Returns whether the decimal value is small enough to be stored in a long.
|
static boolean |
isCompact(int precision)
Returns whether the decimal value is small enough to be stored in a long.
|
int |
precision()
Returns the precision of this
Decimal . |
int |
scale()
Returns the scale of this
Decimal . |
BigDecimal |
toBigDecimal()
Converts this
Decimal into an instance of BigDecimal . |
String |
toString() |
byte[] |
toUnscaledBytes()
Returns a byte array describing the unscaled value of this
Decimal . |
long |
toUnscaledLong()
Returns a long describing the unscaled value of this
Decimal . |
static Decimal |
zero(int precision,
int scale)
Creates an instance of
Decimal for a zero value with the given precision and scale. |
public int precision()
Decimal
.
The precision is the number of digits in the unscaled value.
public int scale()
Decimal
.public BigDecimal toBigDecimal()
Decimal
into an instance of BigDecimal
.public long toUnscaledLong()
Decimal
.ArithmeticException
- if this Decimal
does not exactly fit in a long.public byte[] toUnscaledBytes()
Decimal
.Decimal
.public boolean isCompact()
public int compareTo(@Nonnull Decimal that)
compareTo
in interface Comparable<Decimal>
@Nullable public static Decimal fromBigDecimal(BigDecimal bd, int precision, int scale)
Decimal
from a BigDecimal
and the given precision and
scale.
The returned decimal value may be rounded to have the desired scale. The precision will be checked. If the precision overflows, null will be returned.
public static Decimal fromUnscaledLong(long unscaledLong, int precision, int scale)
Decimal
from an unscaled long value and the given precision
and scale.public static Decimal fromUnscaledBytes(byte[] unscaledBytes, int precision, int scale)
Decimal
from an unscaled byte array value and the given
precision and scale.@Nullable public static Decimal zero(int precision, int scale)
Decimal
for a zero value with the given precision and scale.
The precision will be checked. If the precision overflows, null will be returned.
public static boolean isCompact(int precision)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.