本文介紹了Java中的大數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何在 Java 中進行非常大的數字計算?
How would I go about doing calculations with extremely large numbers in Java?
我已經嘗試過 long
,但它的最大值為 9223372036854775807,當使用整數時,它不能保存足夠的數字,因此對于我的需要來說不夠準確.
I have tried long
but that maxes out at 9223372036854775807, and when using an integer it does not save enough digits and therefore is not accurate enough for what I need.
這里面還有嗎?
推薦答案
您可以將 BigInteger
類用于整數,BigDecimal
用于帶有小數位的數字.這兩個類都定義在 java.math
包中.
You can use the BigInteger
class for integers and BigDecimal
for numbers with decimal digits. Both classes are defined in java.math
package.
例子:
BigInteger reallyBig = new BigInteger("1234567890123456890");
BigInteger notSoBig = new BigInteger("2743561234");
reallyBig = reallyBig.add(notSoBig);
這篇關于Java中的大數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!