题目要求是高精度除法,要求保留N位小数(四舍五入),并且当整数部分为0时去除0的显示
1 import java.math.BigDecimal; 2 import java.util.Scanner; 3 4 public class BD 5 { 6 public static void main(String[] args) 7 { 8 Scanner scanner = new Scanner(System.in); 9 while(scanner.hasNext()) 10 { 11 BigDecimal a = scanner.nextBigDecimal(); 12 BigDecimal b = scanner.nextBigDecimal(); 13 int n = scanner.nextInt(); 14 System.out.println(a.divide(b, n, BigDecimal.ROUND_HALF_UP).toString().replaceFirst("^0*", "")); 15 } 16 } 17 }
时间: 2024-10-11 07:01:16