mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02: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:
@@ -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());
|
||||
}
|
||||
|
||||
+6
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user