Math.round被忽略

时间:2018-08-23 21:02:02

标签: java

    double energy, mass;
    double speedOfLight = 299792458.0;
    // Get mass
    System.out.print("Mass? ");
    mass = keyboard.nextDouble();
    // Calculate energy
    energy = mass*Math.pow(speedOfLight, 2);
    // Round to 1 decimal place
    energy = Math.round(energy * 10.0) / 10.0;
    System.out.printf("The energy is " +energy+ " Joules");
    // Close scanner
    keyboard.close();

返回时应返回“能量为8.987551787368176E16焦耳”

1 个答案:

答案 0 :(得分:4)

ggplot(data = Preference, aes(Preference$First_FTF)) + geom_histogram(binwidth = 0.25, boundary = 0, close = "left") + scale_x_continuous(breaks = 1:4) 可以正常工作,返回最接近的整数(但输出在scientific notation中)。问题出在号码的打印上。您可以使用Math.round的{​​{3}}以所需的格式打印数字:

printf