其他分享
首页 > 其他分享> > 其他类:System、Math、BigInteger和BigDecimal

其他类:System、Math、BigInteger和BigDecimal

作者:互联网

package com.changyonglei.system;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * 其他类:
 * 1.System     --> test1()
 * 2.Math
 * 3.BigInteger --> test2()
 * 4.BigDecimal --> test2()
 *
 * @author Dixon
 * @create 2022-05-30 20:19
 */

public class SystemTest {

    @Test
    public void test1(){
        String javaVersion = System.getProperty("java.version");
        System.out.println("java.version:" + javaVersion);

        String javaHome = System.getProperty("java.home");
        System.out.println("java.home:" + javaHome);

        String osName = System.getProperty("os.name");
        System.out.println("os的name:" + osName);

        String osVersion = System.getProperty("os.version");
        System.out.println("os的version:" + osVersion);

        String userName = System.getProperty("user.name");
        System.out.println("user的name:" + userName);

        String userHome = System.getProperty("user.home");
        System.out.println("user的home:" + userHome);

        String userDir = System.getProperty("user.dir");
        System.out.println("user的dir:" + userDir);
    }

    @Test
    public void test2(){
        BigInteger bi = new BigInteger("12433241123");
        BigDecimal bd = new BigDecimal("12435.351");
        BigDecimal bd2 = new BigDecimal("11");
        System.out.println(bi); //12433241123
//        System.out.println(bd.divide(bd2)); //除不尽就报错
        //四舍五入,保留十五位小数
        System.out.println(bd.divide(bd2,BigDecimal.ROUND_HALF_UP));//1130.486
        //四舍五入,保留十五位小数
        System.out.println(bd.divide(bd2,15,BigDecimal.ROUND_HALF_UP));//1130.486454545454545

    }
}

 

标签:BigInteger,getProperty,BigDecimal,System,String,println,Math,out
来源: https://www.cnblogs.com/Dixon1993/p/16328790.html