zoukankan      html  css  js  c++  java
  • Java

    BigDecimal和BigInteger的区别主要在于除法会除不尽,需要指定精确到小数点后多少位以及舍入方法。

    import java.io.*;
    import java.math.*;
    import java.util.*;
    
    public class Main {
    	public static void main(String[] args) {
    		InputStream inputStream = System.in;
    		OutputStream outputStream = System.out;
    		InputReader in = new InputReader(inputStream);
    		PrintWriter out = new PrintWriter(outputStream);
    		Solver solver = new Solver();
    		solver.solve(in, out);
    		out.close();
    	}
    
    	static class Solver {
    		public void solve(InputReader in, PrintWriter out) {
    			BigDecimal d1=BigDecimal.valueOf(1);
    			BigDecimal d2=BigDecimal.valueOf(7);
    			
    			out.print(d1+"/"+d2+"=");
    			out.println(d1.divide(d2, 30, RoundingMode.HALF_UP));
    		}
    
    	}
    
    	static class InputReader {
    		public BufferedReader reader;
    		public StringTokenizer tokenizer;
    
    		public InputReader(InputStream stream) {
    			reader = new BufferedReader(new InputStreamReader(stream), 32768);
    			tokenizer = null;
    		}
    
    		public String next() {
    			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
    				try {
    					tokenizer = new StringTokenizer(reader.readLine());
    				} catch (IOException e) {
    					throw new RuntimeException(e);
    				}
    			}
    			return tokenizer.nextToken();
    		}
    
    		public int nextInt() {
    			return Integer.parseInt(next());
    		}
    		
    		public long nextLong() {
    			return Long.parseLong(next());
    		}
    
    	}
    	
    }
    
  • 相关阅读:
    金额转中国大写
    double 四舍五入保留一定的位数
    通过ajax提交表单上传文件
    微信扫码提示浏览器打开的
    在Servlet中获取spring容器WebApplicationContext
    Oracle CONNECT by 简单用法
    JS 删除Array对象中的元素。
    数据导出excel
    DWZ 在js中刷新某个navTab
    Python发送邮件
  • 原文地址:https://www.cnblogs.com/Yinku/p/10759793.html
Copyright © 2011-2022 走看看