Package org.openhab.core.library.types
Class DecimalType
java.lang.Object
java.lang.Number
org.openhab.core.library.types.DecimalType
- All Implemented Interfaces:
Serializable
,Comparable<DecimalType>
,Command
,PrimitiveType
,State
,Type
- Direct Known Subclasses:
PercentType
@NonNullByDefault
public class DecimalType
extends Number
implements PrimitiveType, State, Command, Comparable<DecimalType>
The decimal type uses a BigDecimal internally and thus can be used for
integers, longs and floating point numbers alike.
- Author:
- Kai Kreuzer - Initial contribution
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final BigDecimal
protected BigDecimal
static final DecimalType
-
Constructor Summary
ConstructorDescriptionDecimalType
(Number value) Creates a newDecimalType
with the given value.DecimalType
(String value) Creates a newDecimalType
with the given value.DecimalType
(String value, Locale locale) Creates a newDecimalType
with the given value. -
Method Summary
Modifier and TypeMethodDescription<T extends State>
@Nullable TConvert thisState
's value into another typeint
protected <T extends State>
@Nullable TdefaultConversion
(@Nullable Class<T> target) double
boolean
float
Formats the value of this type according to a pattern (seeFormatter
).int
hashCode()
int
intValue()
long
Get a string representation that contains the whole internal representation of the type.toString()
static DecimalType
Static access toDecimalType(String)
.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
BIG_DECIMAL_HUNDRED
-
ZERO
-
value
-
-
Constructor Details
-
DecimalType
public DecimalType() -
DecimalType
Creates a newDecimalType
with the given value.- Parameters:
value
- a number
-
DecimalType
Creates a newDecimalType
with the given value. The English locale is used to determine (decimal/grouping) separator characters.- Parameters:
value
- the value representing a number- Throws:
NumberFormatException
- when the number could not be parsed to aBigDecimal
-
DecimalType
Creates a newDecimalType
with the given value.- Parameters:
value
- the value representing a numberlocale
- the locale used to determine (decimal/grouping) separator characters- Throws:
NumberFormatException
- when the number could not be parsed to aBigDecimal
-
-
Method Details
-
toString
-
toFullString
Description copied from interface:Type
Get a string representation that contains the whole internal representation of the type.The returned string could be consumed by the static 'valueOf(String)' method of the respective type to build a new type that is equal to this type.
- Specified by:
toFullString
in interfaceType
- Returns:
- a full string representation of the type to be consumed by 'valueOf(String)'
-
valueOf
Static access toDecimalType(String)
.- Parameters:
value
- the non null value representing a number- Returns:
- a new
DecimalType
- Throws:
NumberFormatException
- when the number could not be parsed to aBigDecimal
-
format
Description copied from interface:Type
Formats the value of this type according to a pattern (seeFormatter
). -
toBigDecimal
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<DecimalType>
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classNumber
-
floatValue
public float floatValue()- Specified by:
floatValue
in classNumber
-
intValue
public int intValue() -
longValue
public long longValue() -
defaultConversion
-
as
Description copied from interface:State
Convert thisState
's value into another type
-