Java - What is the data type for physical computing?

I am trying to create a physical calculation program in Java. So I used some formulas, but they always returned the wrong value. I split them up and found: (I have used longso far.)

8 * 830584000 = -1945262592

which is obviously wrong. The formulas contain fractions and very high numbers, for example 6.095E23 and 4.218E-10.

So, what type of data is best for getting the right result?

+4
source share
3 answers

, double - . "", , , , , . , 15 .

Java:

8.0 * 830584000, double. 8.0 double , .

.

: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

+3

, BigDecimal - , . , , , , .

+2

Since physical calculations involve many floating point operations, a floating point data type can be a good option in such calculations. Hope this helps. :)

0
source

Source: https://habr.com/ru/post/1692566/


All Articles