package com.kfzs.duanduan.utils;

import java.math.BigDecimal;

/**
 *
 * Created by HooRang on 2017/3/21.
 */
public class NumberFormatUtils {

    private static final int DIVISOR_DEFAULT = 10 ;

    public static float getDivideResult(int dividend){
        if (dividend <= 0){
            return 0.0f;
        }

        BigDecimal bDivisor = new BigDecimal(Double.valueOf(dividend));
        BigDecimal bDividend = new BigDecimal(Double.valueOf(DIVISOR_DEFAULT));
        BigDecimal result = bDivisor.divide(bDividend, 1,BigDecimal.ROUND_HALF_DOWN);

        return result.floatValue();
    }

    public static float getDivideResult(int dividend, int divisor){
        if (dividend <= 0){
            return 0.0f;
        }

        if (divisor > dividend){
            return 0.0f;
        }
        BigDecimal bDivisor = new BigDecimal(Double.valueOf(dividend));
        BigDecimal bDividend = new BigDecimal(Double.valueOf(divisor));
        BigDecimal result = bDivisor.divide(bDividend, 1,BigDecimal.ROUND_HALF_DOWN);

        return result.floatValue();
    }

    public static double decimal(double val, int newScale){
        BigDecimal   b   =   new   BigDecimal(val);
        double   f1   =   b.setScale(newScale,   BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }
}
