mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
解析电表起止值
This commit is contained in:
@@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -274,6 +275,43 @@ public class YKCUtils {
|
||||
return divide.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 减去倍数
|
||||
* @param value
|
||||
* @param magnification
|
||||
* @param scale
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal reduceMagnification(long value, int magnification, int scale) {
|
||||
return new BigDecimal(value).divide(new BigDecimal(magnification), scale, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取5字节小端字节序的数字
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
public static long readLongLE5Byte(byte[] bytes) {
|
||||
// 确保字节数组的长度至少为 5
|
||||
if (bytes.length < 5) {
|
||||
throw new IllegalArgumentException("字节数组长度必须至少为5字节");
|
||||
}
|
||||
|
||||
// 使用小端字节序读取 5 字节数字
|
||||
int byte1 = bytes[0] & 0xFF;
|
||||
int byte2 = bytes[1] & 0xFF;
|
||||
int byte3 = bytes[2] & 0xFF;
|
||||
int byte4 = bytes[3] & 0xFF;
|
||||
int byte5 = bytes[4] & 0xFF;
|
||||
|
||||
// 将读取的字节合并成一个 long 值
|
||||
return ((long) byte1) |
|
||||
((long) byte2 << 8) |
|
||||
((long) byte3 << 16) |
|
||||
((long) byte4 << 24) |
|
||||
((long) byte5 << 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取价格byte数组
|
||||
* 价格转换为byte数组
|
||||
|
||||
Reference in New Issue
Block a user