runden
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-04-09 20:17:35 +02:00
parent 6e94925fda
commit be531a7ccf

View File

@ -177,6 +177,17 @@ function updateRowWithNewData(row, weight, nutritionData) {
}
function schulrunden(zahl) {
// Multipliziere die Zahl mit 10, um die relevante Dezimalstelle vor das Komma zu bekommen
zahl = zahl * 10;
// Wende Math.ceil an, um auf die nächste ganze Zahl aufzurunden,
// aber nur, wenn der Dezimalteil >= 0.5 ist. Andernfalls verwende Math.floor.
zahl = (zahl - Math.floor(zahl) >= 0.5) ? Math.ceil(zahl) : Math.floor(zahl);
// Teile durch 10, um die ursprüngliche Skalierung wiederherzustellen,
// aber mit der erforderlichen Rundung
return zahl / 10;
}
function addProduct() {
const foodInput = document.getElementById('my_combobox');
@ -187,7 +198,7 @@ function updateRowWithNewData(row, weight, nutritionData) {
const portions = portionsInput.value ? parseInt(portionsInput.value, 10) : 1;
// Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden
weight = Math.ceil(weight / portions);
weight = schulrunden(Math.ceil(weight / portions));
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)