Merge branch 'dev/0.8_dataBridge2' into dev/0.9_cockpit
This commit is contained in:
commit
59a1f8dc61
@ -8,6 +8,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -101,14 +102,14 @@ public class CalculateUtils {
|
||||
case '*':
|
||||
return a.multiply(b);
|
||||
case '/':
|
||||
return a.divide(b);
|
||||
return a.divide(b, 6, RoundingMode.HALF_UP);
|
||||
case '%':
|
||||
// 取余,如果不包含小数点,下面length处理会报错,这里做个处理
|
||||
if (!b.toString().contains(".0")) {
|
||||
b = new BigDecimal(b + ".0");
|
||||
}
|
||||
int length = b.toString().split("\\.")[1].length();
|
||||
return a.divide(b, length, BigDecimal.ROUND_HALF_UP);
|
||||
return a.divide(b, length, RoundingMode.HALF_UP);
|
||||
case '^':
|
||||
// 幂运算:a的b次方
|
||||
double result = Math.pow(a.doubleValue(), b.doubleValue());
|
||||
@ -368,7 +369,7 @@ public class CalculateUtils {
|
||||
*/
|
||||
public static String parseValue(String dataType, String hexString) {
|
||||
String value = "";
|
||||
Long val = Long.parseLong(hexString, 16);
|
||||
long val = Long.parseLong(hexString, 16);
|
||||
byte[] bytes = ByteBufUtil.decodeHexDump(hexString);
|
||||
if (StringUtils.isNotEmpty(dataType)) {
|
||||
ModbusDataType type = ModbusDataType.convert(dataType);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user