package com.zy.common.utils;
|
|
import com.core.common.RadixTools;
|
|
import java.math.BigDecimal;
|
|
/**
|
* Created by vincent on 2020-06-03
|
*/
|
public class CommonUtils {
|
|
public static Integer parseInt(Object value){
|
if(null == value){
|
return null;
|
}
|
String name = value.getClass().getSimpleName().toLowerCase();
|
if(name.equals("float")){
|
return ((Float)value).intValue();
|
} else if(name.equals("double")){
|
return ((Double)value).intValue();
|
} else if(name.equals("bigdecimal")) {
|
return ((BigDecimal)value).intValue();
|
} else if(name.equals("long")) {
|
return ((Long)value).intValue();
|
} else if(name.contains("int")) {
|
return (Integer)value;
|
} else {
|
return Double.valueOf(""+value).intValue();
|
}
|
}
|
|
//int转short数组
|
public static short[] intToShorts(int num) {
|
//先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间
|
byte[] bytes = RadixTools.intToBytes(num);
|
byte[] tmp1 = {bytes[0], bytes[1]};
|
short byteToShort = RadixTools.byteToShort(tmp1);
|
byte[] tmp2 = {bytes[2], bytes[3]};
|
short byteToShort2 = RadixTools.byteToShort(tmp2);
|
return new short[]{byteToShort2, byteToShort};
|
}
|
|
}
|