package com.huimv.env.admin.common.utils;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.text.DecimalFormat;
import java.util.Random;

public class NumberUtils {

    public static DecimalFormat df = new DecimalFormat("#,##0.00");
    public static String format(String str) {
        if (StringUtils.isBlank(str)){
            return "0.00";
        }
        return df.format(Double.valueOf(str));
    }
    //num 是小数位数
    public static String getNum(Integer min,Integer max, Integer num) {
        Random rand = new Random();
        int result = rand.nextInt(max - min ) +min;
        if (num >0){
            return result+"."+(rand.nextInt((int) Math.pow(10,num)));
        }
        return  result+"";
    }
    // 是小数位数
    public static String getNumFloat(Double min, Double max) {
        double v = Math.random() * (max - min) + min;
        DecimalFormat df = new DecimalFormat("0.0");
        return df.format(v);
    }

    public static String getNumFloat2(Double min, Double max) {
        double v = Math.random() * (max - min) + min;
        DecimalFormat df = new DecimalFormat("0.00");
        return df.format(v);
    }

    public static String getNumFloat3(Double min, Double max) {
        double v = Math.random() * (max - min) + min;
        DecimalFormat df = new DecimalFormat("0.000");
        return df.format(v);
    }
}
