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
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimalprotected BigDecimalstatic final DecimalType -
Constructor Summary
ConstructorsConstructorDescriptionDecimalType(Number value) Creates a newDecimalTypewith the given value.DecimalType(String value) Creates a newDecimalTypewith the given value.DecimalType(String value, Locale locale) Creates a newDecimalTypewith the given value. -
Method Summary
Modifier and TypeMethodDescription<T extends State>
@Nullable TConvert thisState's value into another typeintprotected <T extends State>
@Nullable TdefaultConversion(@Nullable Class<T> target) doublebooleanfloatFormats the value of this type according to a pattern (seeFormatter).inthashCode()intintValue()longGet a string representation that contains the whole internal representation of the type.toString()static DecimalTypeStatic 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 newDecimalTypewith the given value.- Parameters:
value- a number
-
DecimalType
Creates a newDecimalTypewith 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 newDecimalTypewith 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:TypeGet 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:
toFullStringin 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:TypeFormats the value of this type according to a pattern (seeFormatter). -
toBigDecimal
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<DecimalType>
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
intValue
public int intValue() -
longValue
public long longValue() -
defaultConversion
-
as
Description copied from interface:StateConvert thisState's value into another type
-