Integer与Double类型转换


示例代码

public class Company {
    public static void main(String[] args) {


        // 示例, 支持0.2开头
        String currentVoltage = "20.014";

        // 转换双精度
        int totalFee1 = (int) (Double.parseDouble(currentVoltage));

        // 转换单精度, 有时会使数据值变小;
        int totalFee2 = (int) (Float.parseFloat(currentVoltage));

        // 输出 20 20
        System.out.println("totalFee1:" + totalFee1 + ",totalFee2:" + totalFee2 + ".");
        
    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM