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();
        }
    }
  • 相关阅读:
    Spring shiro学习(二)
    Spring shiro学习(一)
    Redis/zookeeper/ActiveMQ在Mac下的安装配置
    Mac下利用brew安装Intellij IDEA
    MySQL服务相关
    Ruby变量常量
    Web性能测试工具:Siege安装&使用简介
    无限级分类功能实践
    Ubuntu Bash and Dash
    安装好的虚拟机,外部通过ssh工具连接,报connection failed
  • 原文地址:https://www.cnblogs.com/weberweber/p/6590937.html
Copyright © 2011-2022 走看看