English 中文(简体)
是否有一揽子计划来执行。 数量大、高精度?
原标题:Is there a package that implements Very Large, High-precision numbers?

I m finding that i m needing to compute large numbers to high precision. For example: 5422300.8452. What is the best way to store this data so that simple arithmetic operators can act on it? I ve been trying to do combinations of Longs and Doubles but it gets complicated after a significant number of computations. I m sure there is a simple solution, i m just not so knowledgeable yet.

Ok Basically, I figured it out: My problem was that I wanted to keep 4 decimal places of precision but entering a high number started truncating digits. For example, I had this:

Double Remain = (double) Math.round((double quantity/12)*10000)/10000;

这一数字较小,但9 000 000人仍然被拖到7.5件。

So I basically need to divide the numbers as long and then take the modulus of the 2 and divide it by the denominator, and round the result. Then add the 2.

工作!

最佳回答

Ok Basically, I figured it out: My problem was that I wanted to keep 4 decimal places of precision but entering a high number started truncating digits. For example, I had this:

Double Remain = (double) Math.round((double quantity/12)*10000)/10000;

这一数字较小,但9 000 000人仍然被拖到7.5件。

So I basically need to divide the numbers as long and then take the modulus of the 2 and divide.

或许,如果解释我试图做的事情的目的,它会提供帮助。 我希望该守则能够显示一定数量的一些重要数字。 如果我把双倍作为变数来储存用户投入,以便分开,那么许多数位数可能会被缩减(取决于由此造成的小数点)。 我需要一种方法,使数字总数中的变量范围标准化,同时将数字精确到4个小数点。

换言之,我需要能够处理相同的人数,而不管有多少名精准者认为是这样。

In order to do this I take the user input, and divide it by the literal (12). Then I take the modulus the same way and divide the modulus by 12. I then piece the 2 together like so:

Quotient.toString() + Remainder.toString().substring(1)
问题回答

BigInteger和BigDecimal是你重新寻找的课堂。 虽然由于运营商超负荷工作在贾瓦邦就存在,因此,你敢于使用简单的算术操作器。 但是,这些班级都有所有简单作业所需的方法。

I m not sure if I understand your followup question, but in order to divide, the code could look as follows:

BigDecimal x = new BigDecimal(45);
BigDecimal y = new BigDecimal(12);
BigDecimal result = x.divide(y);

由于JB Nizet描述的下游,无法使用任何经营者,因此

BigDecimal x = new BigDecimal(45);
BigDecimal y = new BigDecimal(12);
BigDecimal result = x/y;

赢得工作。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签