Converts an object to a double
public static Double changetyped (Object obj) {
try {
if (obj!=null) {
return new BigDecimal (double.valueof (obj + "")). Setscale (2,
BIGDECIMAL.ROUND_HALF_UP). Doublevalue ();
}else{
return 0.0;
}
} catch (Exception e) {
return 0.0;
}
}
Convert an object to an integer
public static Integer Changetypei (Object obj) {
try {
if (obj!=null) {
return Stringutils.tointeger (obj);
}else{
return 0;
}
} catch (Exception e) {
return 0;
}
}
Converts a string to an integer
public static String changetypes (Object obj) {
try {
return Stringutils.tointeger (obj). toString ();
} catch (Exception e) {
Return "";
}
}
/**
* Set the number 0 in map to null
*
* @param map
* @author: Nqy
* @Createtime: March 24, 2017 9:22:09
*/
public static void Setvalueisnull (map map) {
if (map! = null && map.size () > 0) {
Iterator it = Map.keyset (). Iterator ();
String key = null;
while (It.hasnext ()) {
Key = It.next (). toString ();
Object obj = map.get (key);
if (obj! = null) {
if (Numberutils.isnumber (obj.tostring ())) {
Double val = double.parsedouble (obj.tostring ());
if (val = = 0.0) {
Map.put (key, NULL);
}else if (val%1==0) {
Map.put (key, (int) Math.ceil (val));
}else if (val%1!=0) {
DecimalFormat df = new DecimalFormat ("#.00");
Map.put (Key, Df.format (Val));
}
}
}
}
}
}
/**
* Number of persons processed (single digit) divided by 10000
* @param obj
*/
public static String dealdouble (Object obj) {
DecimalFormat df = new DecimalFormat (dealreportutil.changetyped (obj) <10000? " 0.0000 ":" #.0000 ");
Return Df.format (dealreportutil.changetyped (obj)/10000);
}
Common Object data processing in Java