package com.zt.plat.module.qms.core.qlexpress.function;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.alibaba.qlexpress4.runtime.Parameters;
import com.alibaba.qlexpress4.runtime.QContext;
import com.alibaba.qlexpress4.runtime.function.CustomFunction;


public class RoundToScaleHalfEven implements CustomFunction {

	@Override
	public Object call(QContext qContext, Parameters parameters) throws Throwable {
		if (parameters.size() != 2) {
            throw new Exception("roundToScale函数需要2个参数：数值和小数位数");
        }
        double value = Double.parseDouble(parameters.get(0).get().toString());
        int scale = Integer.parseInt(parameters.get(1).get().toString());
        
        BigDecimal bd = BigDecimal.valueOf(value);
        bd = bd.setScale(scale, RoundingMode.HALF_EVEN);
        return bd;
	}


}
