在方法中四舍五入这个数字

时间:2018-10-13 18:17:29

标签: java

我希望将以千克为单位的重量四舍五入到2 d.p,我将如何在方法中做到这一点?

public String convertFromStoneLbsOz(){ 
    EasyIn2 reader=new EasyIn2();

    System.out.println("Please enter the weight in whole stones.");
        weightInStone=reader.getInt();
    System.out.println("Please enter the weight in whole pounds.");
        weightInLbs=reader.getInt();
    System.out.println("Please enter the weight in whole ounces.");
        weightInOz=reader.getInt();

        weightInKg=Math.round(weightInStone*lbPerStone*ozPerLb/ozPerKg);

        return ("The weight you entered in kg is "+ weightInKg + " kg.");
    }

0 个答案:

没有答案