More efficient way to achieve most decimal numbers after division

I currently have this but it takes forever to run. Is there a faster possible solution?

Code:

`int scale = 1000000;`

BigDecimal num1 = new BigDecimal(103993);

BigDecimal num2 = new BigDecimal(33102);

System.out.println(num1.divide(num2, scale, RoundingMode.HALF_UP).toString());

Re: More efficient way to achieve most decimal numbers after division

Hmm. Define forever. You are calculating a ratio to 10000 digits. What exactly are you trying to do?

Regards,

Jim

Re: More efficient way to achieve most decimal numbers after division

forever being 10 minutes. I feel like there has to be a quick way to calculate it in a few seconds at most What I want to do is to be able to compare similar fractions that display a number close to pi and see at which digits they differ for example the numbers

22/7, 355/113, 103993/33102.

Re: More efficient way to achieve most decimal numbers after division

Well, I ran the snippet you included in the thread and it ran instantly (less than a second).

Jim

Re: More efficient way to achieve most decimal numbers after division

It takes about 50ms when I try it.

And that includes printing the 10K digits which is a bit pointless since they don't need to be read and they mostly consist of 11902604072261494773729684007008639961331641592653 0 repeated over and over again.

Re: More efficient way to achieve most decimal numbers after division

Yeah. I didn't mention the repeating fraction part. My particular segment repeated 195 times. And I ran 100 of these in less than 10 seconds.

Jim

Re: More efficient way to achieve most decimal numbers after division

Sorry I didnt have the correct amount of zeros in that one. With the new code it takes forever

Re: More efficient way to achieve most decimal numbers after division

Okay, well you might want to add some logic to the code to detect when the repetition starts. Rational numbers are either exact or will repeat. And the cycle of repetition is related to the denominator. You can search the web for "decimal expansions" to get more on the subject.

Regards,

Jim

Re: More efficient way to achieve most decimal numbers after division

thanks! I believe thats my problem