摄氏温度华氏温度

    private float convertFahrenheitToCelsius(float fahrenheit) {
        float celsius = (fahrenheit - 32) / 1.8f;
        BigDecimal b = new BigDecimal(celsius);
        celsius = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        return celsius;
    }

    private float getFahrenheitForTruing(float fahrenheit) {
        int integralValue = (int) (fahrenheit + 0.5);

        if (TEMPERATURE_MAX_US < integralValue) {
            return TEMPERATURE_MAX_US;
        } else if (TEMPERATURE_MIM_US > integralValue) {
            return TEMPERATURE_MIM_US;
        } else {
            return (float)integralValue;
        }
    }

    private float convertCelsiusToFahrenheit(float celsius) {
        float fahrenheit = celsius * 1.8f + 32;
        BigDecimal b = new BigDecimal(fahrenheit);
        fahrenheit = b.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
        return fahrenheit;
    }

    private float getCelsiusForTruing(float celsius) {
        int integralValue = (int) celsius;
        float decimalValue = celsius - integralValue;
        float value;

        if (0.0f == decimalValue) {
            value = celsius;
        } else if (0.5f > decimalValue) {
            value = ((float) integralValue + 0.5f);
        } else {
            value = ((float) integralValue + 1.0f);
        }

        if (TEMPERATURE_MAX_CN < value) {
            return TEMPERATURE_MAX_CN;
        } else if (TEMPERATURE_MIM_CN > value) {
            return TEMPERATURE_MIM_CN;
        } else {
            return value;
        }
    }

你可能感兴趣的:(摄氏温度华氏温度)