package top.qaqaq.java.P494;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* 其他常用类的使用
* 1.System
* 2.Math
* 3.BigInteger 和 BigDecimal
*
* @author RichieZhang
* @create 2022-10-23 下午 10:27
*/
public class OtherClassTest {
@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("124332411231231321114411414142141241414142141421231123");
BigDecimal bd = new BigDecimal("12435.351");
BigDecimal bd2 = new BigDecimal("11");
System.out.println(bi);
System.out.println(bd.divide(bd2));
System.out.println(bd.divide(bd2, BigDecimal.ROUND_HALF_UP));
System.out.println(bd.divide(bd2, 25, BigDecimal.ROUND_HALF_UP));
//项目中涉及到计算金额的, 部分代码如下, 编译器提示ROUND_HALF_UP is deprecated. 不推荐使用.
// 从java9就不推荐使用了.修改方案:将BigDecimal.ROUND_HALF_UP改为:RoundingMode.HALF_UP
}
}
暂无评论