import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;
// a/b转为小数,精确到小数点后c位
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = 1;
while (sc.hasNext()) {
String[] strings = sc.nextLine().split(" ");
int a = Integer.parseInt(strings[0]);
int b = Integer.parseInt(strings[1]);
int c = Integer.parseInt(strings[2]);
if (a == 0 && b == 0 && c == 0) {
return;
}
double res = 1.0 * a / b;
BigDecimal num = new BigDecimal(Double.toString(res));
// 需要截尾处理,而不是四舍五入
num = num.setScale(c, RoundingMode.FLOOR);
System.out.println("Case " + count + ": " + num.toString());
count++;
}
}
}
你后来不是过了吗(
我想你已经知道了答案
res
变量精度损失了,res
就该直接上高精度