package com.palatform.yijia;

import org.apache.commons.codec.digest.DigestUtils;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

public class test {

    public static void main(String[] args) {
//        byte[] digesta = {0, 1, 0, 1};
//        byte[] digestb = {0, 0, 0, 1};
//        boolean equal = test.isEqual(digesta, digestb);
//        System.out.println(equal);
        //DigestUtils.sha1();



        BigDecimal b1 = new BigDecimal("64.7024");//24.698,24.702
        BigDecimal b2 = new BigDecimal("1.234");

//        System.out.println(b1.add(b2));
//        System.out.println(b1.subtract(b2));
//        System.out.println(b1.multiply(b2));
        //ROUND_HALF_UP:四舍五入(一般采用这个)
        System.out.println(b1.divide(b2,2,BigDecimal.ROUND_HALF_UP));
        //ROUND_HALF_DOWN:四舍五入，如果结果小数位只比保留位多一位且最后一位为5则不进位
        System.out.println(b1.divide(b2,3,BigDecimal.ROUND_HALF_DOWN));
        //ROUND_UP:始终加一
        System.out.println(b1.divide(b2,3,BigDecimal.ROUND_UP));
        //ROUND_DOWN:直接截取
        System.out.println(b1.divide(b2,3,BigDecimal.ROUND_DOWN));

    }



    public static boolean isEqual(byte[] digesta, byte[] digestb) {
        if (digesta.length != digestb.length) {
            return false;
        }

        int result = 0;
        // time-constant comparison
        for (int i = 0; i < digesta.length; i++) {
            result |= digesta[i] ^ digestb[i];
            System.out.println(digesta[i] ^ digestb[i]);
            //System.out.println(result);
        }
        return result == 0;
    }



}
