标签:style blog color os 使用 java ar div sp
题目要求是高精度除法,要求保留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 }
标签:style blog color os 使用 java ar div sp
原文地址:http://www.cnblogs.com/catdrivedragon/p/3966273.html