📜  如何在java代码示例中将double更改为int

📅  最后修改于: 2022-03-11 14:52:40.443000             🧑  作者: Mango

代码示例1
class Scratch{
    public static void main(String[] args){
        double decimal = 5.7;
        System.out.println( (int) decimal );    //casting
        System.out.println( Math.round(decimal * 10) / (double) 10);    //Math.round()
        System.out.println( decimal % 1);    // modulus
        System.out.println( Integer.parseInt( String.valueOf(decimal).substring(0, String.valueOf(decimal).indexOf(".")))); // .substring()
    }
}