mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
Do not create new BigDecimals
if a given object is already BigDecimal
(#4177)
Signed-off-by: Martin Grześlowski <martin.grzeslowski@gmail.com>
This commit is contained in:
parent
3a435ec1e7
commit
846877e598
@ -55,6 +55,8 @@ public class DecimalType extends Number implements PrimitiveType, State, Command
|
||||
this.value = type.toBigDecimal();
|
||||
} else if (value instanceof HSBType type) {
|
||||
this.value = type.toBigDecimal();
|
||||
} else if (value instanceof BigDecimal decimal) {
|
||||
this.value = decimal;
|
||||
} else {
|
||||
this.value = new BigDecimal(value.toString());
|
||||
}
|
||||
|
@ -169,7 +169,12 @@ public class QuantityType<T extends Quantity<T>> extends Number
|
||||
*/
|
||||
public QuantityType(Number value, Unit<T> unit) {
|
||||
// Avoid scientific notation for double
|
||||
BigDecimal bd = new BigDecimal(value.toString());
|
||||
BigDecimal bd;
|
||||
if (value instanceof BigDecimal decimal) {
|
||||
bd = decimal;
|
||||
} else {
|
||||
bd = new BigDecimal(value.toString());
|
||||
}
|
||||
quantity = (Quantity<T>) Quantities.getQuantity(bd, unit, Scale.RELATIVE);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user