zoukankan      html  css  js  c++  java
  • java复习(4)数字处理类

    java本身自带一些封装好的类方便数字问题的处理,review下方便以后使用

    DecimalFormat类 可格式化数字格式,控制输出格式

    Math类 提供三角函数、指数函数、取整函数、最大最小函数、随机数等方法,方便运算

    BigInteger类 提供大整数运算操作

    BigDecimal类 提供大浮点数运算操作

    package re04;
    import java.text.DecimalFormat;
    import java.lang.Math;
    import java.math.*;
    /**
     * Description: 数字类处理
     * 
     * @author weber DateTime 2017年3月20日 下午6:24:03
     */
    public class DigitalTest {
    
        //DecimalFormat 样例
        public static String tryFormat(String s, int value){
            DecimalFormat myFormat = new DecimalFormat(s);
            String ans = myFormat.format(value);
            return ans;
        }
        
        //Math样例
        public static void tryMath()
        {
            double res = Math.sin(Math.PI/2);
            res= 1 + Math.log10(res);
            res = Math.pow(res,res);
            System.out.println(Math.rint(res));
        }
        
        //Random样例
        public static void tryRandom()
        {
            int s=(int)(Math.random()*5);
            System.out.println(s);
        }
        
        //BigInteger样例
        public static void tryBigInteger()
        {
            BigInteger t = new BigInteger("123456789");
            System.out.println(t.multiply(t));
        }
        
        public static void main(String[] args){
            String s="###,###,###";
            System.out.println(tryFormat(s,123456789));
            tryMath();
            tryRandom();
            tryBigInteger();
        }
    }
  • 相关阅读:
    提取BioGRID中的基因symbol和得分所在列
    windows端同步数据到samba共享
    C++的基本语法
    上传文件到服务器功能
    django数据库的使用
    django文件的下载实现
    获取文本域输入的内容
    js的if判断
    ajax的使用
    Oracle ADG备库新增变为一主多从
  • 原文地址:https://www.cnblogs.com/weberweber/p/6590937.html
Copyright © 2011-2022 走看看