public class DecimalItem extends Object implements NumberItem<BigDecimal>
A Decimal - despite it's name - is essentially the same thing as an Integer,
but has an implied divisor of 1000 (in other words, a scale of 3). Thus, a
value represented as 0.5
in a field value will be internally stored
as long
with value 500
. The only difference to
IntegerItem
is that get()
will return a BigDecimal
,
and that the implied divisor is taken into account when serializing the
value. getAsLong()
provides access to the raw value when the
overhead of BigDecimal
is not needed.
Modifier and Type | Method and Description |
---|---|
BigDecimal |
get() |
long |
getAsLong() |
int |
getDivisor()
Returns the divisor to be used to obtain the actual numerical value (as
opposed to the underlying long value returned by
LongSupplier.getAsLong() ). |
Parameters |
getParams()
Get the
Parameters of this Item . |
String |
serialize()
Serialize.
|
StringBuilder |
serializeTo(StringBuilder sb)
Serialize to an existing
StringBuilder . |
static DecimalItem |
valueOf(BigDecimal value)
Creates a
DecimalItem instance representing the specified
BigDecimal value, with potential rounding. |
static DecimalItem |
valueOf(long value)
Creates a
DecimalItem instance representing the specified
long value, where the implied divisor is 1000 . |
DecimalItem |
withParams(Parameters params)
Given an existing
Item , return a new instance with the specified
Parameters . |
public static DecimalItem valueOf(long value)
DecimalItem
instance representing the specified
long
value, where the implied divisor is 1000
.value
- a long
value.DecimalItem
representing value
.public static DecimalItem valueOf(BigDecimal value)
DecimalItem
instance representing the specified
BigDecimal
value, with potential rounding.value
- a BigDecimal
value.DecimalItem
representing value
.public DecimalItem withParams(Parameters params)
Parametrizable
Item
, return a new instance with the specified
Parameters
.withParams
in interface Item<BigDecimal>
withParams
in interface NumberItem<BigDecimal>
withParams
in interface Parametrizable<BigDecimal>
params
- Parameters
to set (must be non-null)Parameters
.public Parameters getParams()
Parametrizable
Parameters
of this Item
.getParams
in interface Parametrizable<BigDecimal>
public StringBuilder serializeTo(StringBuilder sb)
Type
StringBuilder
.serializeTo
in interface Type<BigDecimal>
sb
- where to serialize toStringBuilder
so calls can be chained.public String serialize()
Type
serialize
in interface Type<BigDecimal>
public BigDecimal get()
get
in interface Supplier<BigDecimal>
public long getAsLong()
getAsLong
in interface LongSupplier
public int getDivisor()
NumberItem
LongSupplier.getAsLong()
).getDivisor
in interface NumberItem<BigDecimal>
1
for Integers, 1000
for Decimals)Copyright © 2021 The Apache Software Foundation. All rights reserved.