Java BigDecimal转Integer
2021-10-14 本文已影响0人
东本三月
/**
* Map里的数据,如果值为BigDecimal类型,转为Integer
* @param maps
* @return
*/
public static Map mapBigDecimalToInteger(Map maps){
if(maps==null){
return maps;
}
if(maps.isEmpty()){
return maps;
}
for (Object key : maps.keySet()) {
Object value=maps.get(key);
if(value instanceof BigDecimal ){
BigDecimal value_bd=(BigDecimal)value;
value_bd=value_bd.setScale( 0, BigDecimal.ROUND_DOWN );
Integer value_int=Integer.parseInt(value_bd.toString());
maps.put(key,value_int);
}
}
return maps;
}