package com.yihu.jw.healthCare.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Date;

/**
 * @Author: lcp
 * @Date: 2020/7/6 21:28
 */
public class ConvertUtils {

    private static String[] trueStrings = new String[]{"1", "true", "y", "on", "yes"};

    public ConvertUtils() {
    }

    public static String toString(Object obj, String defaults) {
        String rlt;
        try {
            rlt = obj.toString();
        } catch (Exception var4) {
            rlt = defaults;
        }

        return rlt;
    }

    public static String toString(Object obj) {
        return toString(obj, (String)null);
    }

    public static Integer toInt(Object obj, Integer defaults) {
        Integer rlt;
        try {
            rlt = Integer.parseInt(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }

        return rlt;
    }

    public static int toInt(Object obj) {
        return toInt(obj, 0);
    }


    public static Long toLong(Object obj, Long defaults) {
        Long rlt;
        try {
            rlt = Long.parseLong(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }

        return rlt;
    }

    public static long toLong(Object obj) {
        return toLong(obj, 0L);
    }



    public static Double toDouble(Object obj, Double defaults) {
        Double rlt;
        try {
            rlt = Double.parseDouble(obj.toString());
        } catch (Exception var4) {
            rlt = defaults;
        }

        return rlt;
    }

    public static double toDouble(Object obj) {
        return toDouble(obj, 0.0D);
    }


    public static BigDecimal formatDecimal(BigDecimal num, String format) {
        DecimalFormat df = new DecimalFormat(format);
        return new BigDecimal(df.format(num));
    }
}
