zoukankan      html  css  js  c++  java
  • Java中数字操作

    public static void main(String[] args) throws Exception
    {
        {
            //Math函数的四舍五入,注意负数的时候小数位<=0.5都会被舍去,>0.5的才会被进位
            System.out.println(Math.round(15.5));
            System.out.println(Math.round(-15.5));
            System.out.println(Math.round(-15.51));
        }
        {
            //用Random类生成随机数
            List<Integer> intList = new ArrayList<Integer>();
            Random random = new Random();
            int count = 0;
            while(count <= 7)
            {
                Integer tem = random.nextInt(37);
                if(intList.contains(tem))
                    continue;
                else
                {
                    intList.add(tem);
                    count++; 
                }
            }
            
            System.out.println(intList);
        }
        {
            //大整数的加减乘除
            BigInteger bigA = new BigInteger("132122332323232323");
            BigInteger bigB = new BigInteger("45648945649874645645645641231974816");
            System.out.println(bigA);
            System.out.println(bigB);
            System.out.println(bigA.multiply(bigB));
        }
        {
            //大小数的四舍五入
            BigDecimal bd = new BigDecimal("12358645.22564");
            System.out.println(bd.divide(new BigDecimal("1"), 1, BigDecimal.ROUND_HALF_UP));;
        }
    }
  • 相关阅读:
    验证 Email
    取系统时间
    DbHelperSQL.cs
    显示BYTE流图片
    [原]c# 读取文本文件(txt)
    数据库文件组和文件的作用
    Transact—SQL
    m_pMainWnd
    sql server 2005 window 身份证验证模式与SQL Server身份验证
    WM_CLOSE WM_DESTROY WM_QUIT
  • 原文地址:https://www.cnblogs.com/kuillldan/p/5926140.html
Copyright © 2011-2022 走看看