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());
    		}
    
    	}
    	
    }
    
  • 相关阅读:
    Nginx 限流配置
    Nginx 跨域配置
    LVS实现负载均衡原理及安装配置详解
    Tomcat基本概念
    Hapoxy 基本配置概念
    rsync断点续传
    Nginx概念
    angular img标签使用err-src
    $ionicLoading自定义加载动画
    h5+jquery自制相机,获取图片并上传
  • 原文地址:https://www.cnblogs.com/Yinku/p/10759793.html
Copyright © 2011-2022 走看看