Made calculations more precise

This commit is contained in:
2025-01-20 14:29:26 +01:00
parent 4ed86f7420
commit 6e1fb749ad
2 changed files with 17 additions and 10 deletions

View File

@ -2,7 +2,7 @@ package de.vorsorge.theo.util;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.math.MathContext;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -162,14 +162,13 @@ public class FabianUtil {
@Override
public void log() {
BigDecimal counter = getCounter();
BigDecimal percentage = BigDecimal.valueOf(100).divide(total, 15, RoundingMode.HALF_UP).multiply(counter);
BigDecimal percentage = BigDecimal.valueOf(100).divide(total, MathContext.DECIMAL64).multiply(counter);
Duration timePassed = getTimePassed();
String remainingTimePart = "";
if (counter.signum() != 0) {
BigDecimal secondsPassed = BigDecimal.valueOf(timePassed.getSeconds());
BigDecimal totalSeconds = secondsPassed.divide(counter, 15, RoundingMode.HALF_UP).multiply(total);
BigDecimal totalSeconds = secondsPassed.divide(counter, MathContext.DECIMAL64).multiply(total);
BigDecimal secondsToGo = totalSeconds.subtract(secondsPassed);
Duration timeToGo = Duration.of(secondsToGo.longValue(), ChronoUnit.SECONDS);
remainingTimePart = ", " + formatDuration(timeToGo) + " verbleibend";