G
Guest
Gast
Hier eine Methode zu wWurzelberechnung:
Doch beim ausführen kommt:
Was muss ich ändern?
static BigDecimal wurzelBD(long a)
{
BigDecimal x=BigDecimal.valueOf(a).divide(BigDecimal.valueOf(2));
for (int i=0;i<1000;i++)
{
x=(x.add(BigDecimal.valueOf(a).divide(x))).divide(BigDecimal.valueOf(2, 100));
}
x.setScale(100, BigDecimal.ROUND_HALF_UP);
return x;
}
Doch beim ausführen kommt:
Code:
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
Was muss ich ändern?