Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java大数值 #26

Open
yankewei opened this issue May 7, 2020 · 0 comments
Open

Java大数值 #26

yankewei opened this issue May 7, 2020 · 0 comments
Labels
Java 有关 Java 语言的

Comments

@yankewei
Copy link
Owner

yankewei commented May 7, 2020

今天有点不想写,但还是要坚持吧,选一个小节写一下吧。
我们知道Java的基本类型中包含了整型和浮点型,并且这些类型可以做运算,但是有时我们可能会碰到整型或浮点型无法满足我们的需求,这时就可以使用java的math包,有两个非常很有用的类BigIntegerBigDecimal,这两个类可以处理包含任意长度数字序列的数值。
使用静态的valueOf方法可以将普通的数值转换为大数值。

BigInteger a = BigInteger.valueOf(100)

但是,这个类型不能使用我们熟悉的算术运算符,而是需要使用类中定义的方法。

BigInteger a = BigInteger.valueOf(100);
System.out.println(a.subtract(BigInteger.valueOf(50))); // output: 50

更多Api可查看文档

@yankewei yankewei added the Java 有关 Java 语言的 label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java 有关 Java 语言的
Projects
None yet
Development

No branches or pull requests

1 participant