package com.steering.pss.judge.comm;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class RoundGBT81702008 {
	
	/**
	 * 4舍6入5单双（奇进偶不进）
	 * @param value
	 * @return
	 */
	public static double round3_2(double value, int round){
		NumberFormat nfFormat = NumberFormat.getInstance();  
        nfFormat.setMaximumFractionDigits(round);
        nfFormat.setGroupingUsed(false);
        return Double.parseDouble(nfFormat.format(value));
	}
	
	/**
	 * 4舍6入5单双（奇进偶不进）
	 * @param value
	 * @return
	 */
	public static String round3_2String(double value, int round){
		String format = "0";
		for(int i = 0; i < round; i++){
			if(i == 0){
				format += ".0";
			}else{
				format += "0";
			}
		}
		DecimalFormat nfFormat = new DecimalFormat(format); 
        nfFormat.setMaximumFractionDigits(round);
        nfFormat.setGroupingUsed(false);
        return nfFormat.format(value);
	}
	
	/**
	 * 0.5单位修约
	 * @param value
	 * @param round
	 * @return
	 */
	public static double round3_4_1(double value){
		value = value * 2;
		value = round3_2(value, 0);
		value = value / 2;
		return value;
	}
	
	/**
	 * 0.2单位修约
	 * 
	 * @param value
	 * @param round
	 * @return
	 */
	public static double round3_4_2(double value){
		value = value * 5;
		value = round3_2(value, 0);
		value = value / 5;
		return value;
	}
	
	/**
	 * 0.1单位修约 （没有3.4.3 自己造的。）
	 * 
	 * @param value
	 * @param round
	 * @return
	 */
	public static double round3_4_3(double value){
		value = value * 10;
		value = round3_2(value, 0);
		value = value / 10;
		return value;
	}
	
	/**
     * 水压英制圆整 
     * @param value 公制压力
     * @param psi
     * @return
     */
    public static double roundPsi(double value, int psi){
    	value = value / 0.006895;
    	value = value / psi;
    	value = round3_2(value, 0);
    	value = value * psi;
    	return value;
    }
}
