美文网首页Android Utils
摄氏温度华氏温度

摄氏温度华氏温度

作者: 几千里也 | 来源:发表于2015-12-18 12:26 被阅读18次
        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;
            }
        }
    

    相关文章

      网友评论

        本文标题:摄氏温度华氏温度

        本文链接:https://www.haomeiwen.com/subject/iapphttx.html