public class ScaledDecimal extends Object implements Comparable<ScaledDecimal>, Serializable
Modifier and Type | Field and Description |
---|---|
static int |
MAX_LEN
String representation max length: sign + mantissa + exponent = 1 + 20 + 63.
|
Constructor and Description |
---|
ScaledDecimal()
Constructor.
|
ScaledDecimal(BigDecimal bigDecimal)
Constructor.
|
ScaledDecimal(byte[] buffer,
int offset,
int length)
Constructor.
|
ScaledDecimal(long mantissa,
int exponent)
Constructor.
|
ScaledDecimal(String number)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ScaledDecimal o)
Compares to the provided object.
|
boolean |
equals(Object obj) |
int |
getExponent()
Method that returns the exponent part of the scaled decimal as an integer
|
long |
getMantissa()
Method that returns the mantissa part of the scaled decimal as a long
|
int |
hashCode() |
void |
normalize()
Removes non-significant zeros from the scaled decimal.
|
void |
normalize(int newExponent)
Normalize mantissa to the specified exponent.
|
void |
set(BigDecimal bigDecimal)
Sets from big decimal representation.
|
void |
set(byte[] buffer,
int offset,
int length)
Sets from byte array.
|
void |
set(String number)
Sets from string representation.
|
void |
setExponent(int exponent)
Method that sets the value of the exponent part of the scaled decimal.
|
void |
setMantissa(long mantissa)
Method that sets the value of the mantissa part of the scaled decimal.
|
BigDecimal |
toBigDecimal()
Converts to
BigDecimal representation. |
int |
toByteArray(byte[] buffer,
int offset)
Converts to byte array.
|
String |
toString() |
public static final int MAX_LEN
public ScaledDecimal(long mantissa, int exponent)
mantissa
- the mantissa representing the numberexponent
- the exponent representing the numberIllegalArgumentException
- if (exponent < -63)
or (exponent > 63)
public ScaledDecimal(String number)
number
- string representation of a numberNumberFormatException
- if the string format is incorrectNullPointerException
- if (number == null)
public ScaledDecimal(BigDecimal bigDecimal)
bigDecimal
- source value objectNullPointerException
- if (bigDecimal == null)
public ScaledDecimal(byte[] buffer, int offset, int length)
buffer
- source bufferoffset
- offset in the source bufferlength
- length of the value in the source bufferNullPointerException
- if (buffer == null)
IllegalArgumentException
- if (offset < 0)
or (length < 1)
or (offset + length > buffer.length)
public ScaledDecimal()
public final void set(BigDecimal bigDecimal)
bigDecimal
- source value objectNullPointerException
- if (bigDecimal == null)
public final void set(String number)
number
- source stringNullPointerException
- if (number == null)
NumberFormatException
- if the string format is incorrectpublic final void set(byte[] buffer, int offset, int length)
buffer
- source bufferoffset
- offset in the source bufferlength
- length of the value in the source bufferNullPointerException
- if (buffer == null)
IllegalArgumentException
- if (offset < 0)
or (length < 1)
or (offset + length > buffer.length)
NumberFormatException
- if the value parsing failspublic final int getExponent()
public final long getMantissa()
public final void setMantissa(long mantissa)
mantissa
- a value of the mantissa part of the scaled decimalpublic final void setExponent(int exponent)
exponent
- the exponentIllegalArgumentException
- if (exponent < -63)
or (exponent > 63)
public int compareTo(ScaledDecimal o)
compareTo
in interface Comparable<ScaledDecimal>
o
- object to compare toNullPointerException
- if (o == null)
public final BigDecimal toBigDecimal()
BigDecimal
representation.BigDecimal
representationpublic final int toByteArray(byte[] buffer, int offset)
Please note that produced byte array is based on parsed values but not the source raw number (so in case of overflow they may be different).
buffer
- the buffer to useoffset
- offset in the buffer to start withNullPointerException
- if (buffer == null)
IllegalArgumentException
- if (offset < 0)
or (offset >= buffer.length)
IndexOutOfBoundsException
- if there is no enough spacepublic final void normalize()
public final void normalize(int newExponent)
newExponent
- new exponent.IllegalArgumentException
- if converting to new exponent causes data loss in mantissa.Copyright © 2005–2024 Onix Solutions. All rights reserved.