package com.zztrapp.zztrapp.utilcode.mUtil;

import java.lang.reflect.Field;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.HashMap;

/**
 * Describe
 * Created by Bby on 2022/7/8
 * Email bby0856@163.com
 */
public class MyUtil {
    public static String numFormat(int num) {
        String s = "";
        if (num < 10) {
            return "0" + num;
        }
        return String.valueOf(num);
    }

    //对象转Map
    public static HashMap<String, Object> getObjectToMap(Object obj) throws IllegalAccessException {
        HashMap<String, Object> map = new HashMap<String, Object>();
        Class<?> clazz = obj.getClass();
//        System.out.println(clazz);
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(obj);
//            if (value == null) {
//                value = "";
//            }
            map.put(fieldName, value);
        }
        return map;
    }

    public static String getNumberPoint5(double number) {
        DecimalFormat df = new DecimalFormat("#.######");
        df.setRoundingMode(RoundingMode.HALF_DOWN);
        return df.format(number);

    }


}
