我有这段代码:
import java.util.Scanner;
public class DecimalPoints {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("a: "); // printing output
String text_1 = scanner.nextLine(); // taking input
double d1 = Double.parseDouble(text_1); // parsing double from input
System.out.println("b: "); // printing output
String text_2 = scanner.nextLine(); // taking input
double d2 = Double.parseDouble(text_2); // parsing double from input
double d3 = d1 / d2;
d3 = Math.round(d3 * 100) / 100.0d;
System.out.println("Result: " + d3);
}
}
它需要两个输入并将其四舍五入到两位小数,但问题是它会将结果四舍五入。假设我输入a = 513和b = 791,结果将是0.65但是当我检查我的计算器时它显示我0.648 ...有谁知道如何将数字保留在0.64?非常感谢。