Parse BigInteger directly in DecimalType (#4417)

* Parse BigInteger directly in DecimalType

Signed-off-by: Martin Grześlowski <martin.grzeslowski@gmail.com>
This commit is contained in:
Martin 2024-10-20 16:01:59 +02:00 committed by GitHub
parent d431013198
commit 1325d80343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,7 @@
package org.openhab.core.library.types; package org.openhab.core.library.types;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParsePosition; import java.text.ParsePosition;
@ -57,6 +58,8 @@ public class DecimalType extends Number implements PrimitiveType, State, Command
this.value = type.toBigDecimal(); this.value = type.toBigDecimal();
} else if (value instanceof BigDecimal decimal) { } else if (value instanceof BigDecimal decimal) {
this.value = decimal; this.value = decimal;
} else if (value instanceof BigInteger integer) {
this.value = new BigDecimal(integer);
} else { } else {
this.value = new BigDecimal(value.toString()); this.value = new BigDecimal(value.toString());
} }