zoukankan      html  css  js  c++  java
  • java常用的object数据处理

    // 将Object转换为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;
    }
    }
    // 将Object转换为Integer
    public static Integer changeTypeI(Object obj) {
    try {
    if(obj!=null){
    return StringUtils.toInteger(obj);
    }else{
    return 0;
    }
    } catch (Exception e) {
    return 0;
    }
    }

    // 将String转换为Integer
    public static String changeTypeS(Object obj) {
    try {
    return StringUtils.toInteger(obj).toString();
    } catch (Exception e) {
    return "";
    }
    }

    /**
    * 将Map中数字为0的设置为null
    *
    * @param map
    * @author: NQY
    * @Createtime: 2017年3月24日 上午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));
    }
    }
    }
    }
    }
    }
    /**
    * 处理人数(个位数)除以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);
    }

  • 相关阅读:
    thinkphp 5 隐藏index.php
    jquery ajax参数
    图标字的使用方法
    jquery监听浏览宽度
    手机屏幕的宽度自动适应
    前站常用代码
    服务消费者(Feign-上)
    服务消费者(Ribbon)
    注册中心(Eureka/Consul)
    JDK8 日期格式化
  • 原文地址:https://www.cnblogs.com/shuzhenzhumo/p/9298078.html
Copyright © 2011-2022 走看看