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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static BigDecimal
BIG_DECIMAL_HUNDRED
protected BigDecimal
value
static DecimalType
ZERO
-
Constructor Summary
Constructors Constructor Description DecimalType()
DecimalType(double value)
DecimalType(long value)
DecimalType(Number value)
DecimalType(String value)
Creates a newDecimalType
with the given value.DecimalType(String value, Locale locale)
Creates a newDecimalType
with the given value.DecimalType(BigDecimal value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends State>
@Nullable Tas(@Nullable Class<T> target)
Convert thisState
's value into another typeint
compareTo(DecimalType o)
protected <T extends State>
@Nullable TdefaultConversion(@Nullable Class<T> target)
double
doubleValue()
boolean
equals(@Nullable Object obj)
float
floatValue()
String
format(String pattern)
Formats the value of this type according to a pattern (seeFormatter
).int
hashCode()
int
intValue()
long
longValue()
BigDecimal
toBigDecimal()
String
toFullString()
Get a string representation that contains the whole internal representation of the type.String
toString()
static DecimalType
valueOf(String value)
Static access toDecimalType(String)
.-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Field Detail
-
BIG_DECIMAL_HUNDRED
protected static final BigDecimal BIG_DECIMAL_HUNDRED
-
ZERO
public static final DecimalType ZERO
-
value
protected BigDecimal value
-
-
Constructor Detail
-
DecimalType
public DecimalType()
-
DecimalType
public DecimalType(Number value)
-
DecimalType
public DecimalType(BigDecimal value)
-
DecimalType
public DecimalType(long value)
-
DecimalType
public DecimalType(double value)
-
DecimalType
public DecimalType(String value)
Creates a newDecimalType
with the given value. The English locale is used to determine (decimal/grouping) separator characters.- Parameters:
value
- the non null value representing a number- Throws:
NumberFormatException
- when the number could not be parsed to aBigDecimal
-
DecimalType
public DecimalType(String value, Locale locale)
Creates a newDecimalType
with the given value.- Parameters:
value
- the non null 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 Detail
-
toFullString
public String 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
public static DecimalType valueOf(String value)
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
public String format(String pattern)
Description copied from interface:Type
Formats the value of this type according to a pattern (seeFormatter
).
-
toBigDecimal
public BigDecimal toBigDecimal()
-
compareTo
public int compareTo(DecimalType o)
- Specified by:
compareTo
in interfaceComparable<DecimalType>
-
doubleValue
public double doubleValue()
- Specified by:
doubleValue
in classNumber
-
floatValue
public float floatValue()
- Specified by:
floatValue
in classNumber
-
defaultConversion
protected <T extends State> @Nullable T defaultConversion(@Nullable Class<T> target)
-
-