| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | /** |
| | | * Created by JLChen on 2019/7/25 |
| | |
| | | |
| | | /** |
| | | * 将object转为Integer类型 |
| | | * |
| | | * @param object |
| | | * @return |
| | | */ |
| | | public static Integer getIntegerByObject(Object object){ |
| | | public static Integer getIntegerByObject(Object object) { |
| | | Integer in = null; |
| | | if(object!=null){ |
| | | if(object instanceof Integer){ |
| | | in = (Integer)object; |
| | | }else if(object instanceof String){ |
| | | in = Integer.parseInt((String)object); |
| | | }else if(object instanceof Double){ |
| | | in = (int)((double)object); |
| | | }else if(object instanceof Float){ |
| | | in = (int)((float)object); |
| | | }else if(object instanceof BigDecimal){ |
| | | in = ((BigDecimal)object).intValue(); |
| | | }else if(object instanceof Long){ |
| | | in = ((Long)object).intValue(); |
| | | if (object != null) { |
| | | if (object instanceof Integer) { |
| | | in = (Integer) object; |
| | | } else if (object instanceof String) { |
| | | in = Integer.parseInt((String) object); |
| | | } else if (object instanceof Double) { |
| | | in = (int) ((double) object); |
| | | } else if (object instanceof Float) { |
| | | in = (int) ((float) object); |
| | | } else if (object instanceof BigDecimal) { |
| | | in = ((BigDecimal) object).intValue(); |
| | | } else if (object instanceof Long) { |
| | | in = ((Long) object).intValue(); |
| | | } |
| | | } |
| | | return in; |
| | |
| | | |
| | | /** |
| | | * int类型转4字节byte数组 |
| | | * |
| | | * @param mInt |
| | | * @return 4字节byte数组 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * byte[]转int |
| | | * |
| | | * @param bytes |
| | | * @return |
| | | */ |
| | |
| | | |
| | | |
| | | public static float byte2Float(byte[] bytes) { |
| | | if (bytes.length != 4) { |
| | | /* if (bytes.length != 4) { |
| | | return 0; |
| | | } |
| | | }*/ |
| | | byte b[] = bytes; |
| | | ByteBuffer buf = ByteBuffer.allocateDirect(4); |
| | | // buf=buf.order(ByteOrder.LITTLE_ENDIAN);小端用这行代码,默认大端转换 |
| | | buf = buf.order(ByteOrder.LITTLE_ENDIAN);//小端用这行代码,默认大端转换 |
| | | buf.put(b); |
| | | buf.rewind(); |
| | | float f2 = buf.getFloat(); |
| | |
| | | |
| | | /** |
| | | * 调整int 类型参数 |
| | | * |
| | | * @return progress |
| | | */ |
| | | public static int getTrueProgressInt(int progress) { |