From a3110fde21a769b79c604457ef56246b47f18277 Mon Sep 17 00:00:00 2001 From: Cardillan <122014763+cardillan@users.noreply.github.com> Date: Fri, 29 Nov 2024 17:59:17 +0100 Subject: [PATCH 1/2] Properly rounding numbers for display (#10354) --- core/src/mindustry/logic/LExecutor.java | 8 ++++---- core/src/mindustry/logic/LogicDialog.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index e74d4134af..588c02583a 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -966,8 +966,8 @@ public class LExecutor{ exec.textBuffer.append(strValue); }else{ //display integer version when possible - if(Math.abs(value.numval - (long)value.numval) < 0.00001){ - exec.textBuffer.append((long)value.numval); + if(Math.abs(value.numval - (long)(value.numval+0.5)) < 0.00001){ + exec.textBuffer.append((long)(value.numval+0.5)); }else{ exec.textBuffer.append(value.numval); } @@ -1027,8 +1027,8 @@ public class LExecutor{ exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, strValue); }else{ //display integer version when possible - if(Math.abs(value.numval - (long)value.numval) < 0.00001){ - exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, (long)value.numval + ""); + if(Math.abs(value.numval - (long)(value.numval+0.5)) < 0.00001){ + exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, (long)(value.numval+0.5) + ""); }else{ exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, value.numval + ""); } diff --git a/core/src/mindustry/logic/LogicDialog.java b/core/src/mindustry/logic/LogicDialog.java index 18b6dc32a2..eb0cc560e2 100644 --- a/core/src/mindustry/logic/LogicDialog.java +++ b/core/src/mindustry/logic/LogicDialog.java @@ -188,7 +188,7 @@ public class LogicDialog extends BaseDialog{ Label label = out.add("").style(Styles.outlineLabel).padLeft(4).padRight(4).width(140f).wrap().get(); label.update(() -> { if(counter[0] < 0 || (counter[0] += Time.delta) >= period){ - String text = s.isobj ? PrintI.toString(s.objval) : Math.abs(s.numval - (long)s.numval) < 0.00001 ? (long)s.numval + "" : s.numval + ""; + String text = s.isobj ? PrintI.toString(s.objval) : Math.abs(s.numval - (long)(s.numval+0.5)) < 0.00001 ? (long)(s.numval+0.5) + "" : s.numval + ""; if(!label.textEquals(text)){ label.setText(text); if(counter[0] >= 0f){ From 18955d6604ed7af440108e474ddd220f2477c3ed Mon Sep 17 00:00:00 2001 From: Cardillan <122014763+cardillan@users.noreply.github.com> Date: Sat, 30 Nov 2024 16:09:15 +0100 Subject: [PATCH 2/2] Properly rounding numbers for display - fix for negative numbers (#10355) --- core/src/mindustry/logic/LExecutor.java | 8 ++++---- core/src/mindustry/logic/LogicDialog.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 588c02583a..0c4a4eb662 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -966,8 +966,8 @@ public class LExecutor{ exec.textBuffer.append(strValue); }else{ //display integer version when possible - if(Math.abs(value.numval - (long)(value.numval+0.5)) < 0.00001){ - exec.textBuffer.append((long)(value.numval+0.5)); + if(Math.abs(value.numval - Math.round(value.numval)) < 0.00001){ + exec.textBuffer.append(Math.round(value.numval)); }else{ exec.textBuffer.append(value.numval); } @@ -1027,8 +1027,8 @@ public class LExecutor{ exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, strValue); }else{ //display integer version when possible - if(Math.abs(value.numval - (long)(value.numval+0.5)) < 0.00001){ - exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, (long)(value.numval+0.5) + ""); + if(Math.abs(value.numval - Math.round(value.numval)) < 0.00001){ + exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, Math.round(value.numval) + ""); }else{ exec.textBuffer.replace(placeholderIndex, placeholderIndex + 3, value.numval + ""); } diff --git a/core/src/mindustry/logic/LogicDialog.java b/core/src/mindustry/logic/LogicDialog.java index eb0cc560e2..1dd6907e98 100644 --- a/core/src/mindustry/logic/LogicDialog.java +++ b/core/src/mindustry/logic/LogicDialog.java @@ -188,7 +188,7 @@ public class LogicDialog extends BaseDialog{ Label label = out.add("").style(Styles.outlineLabel).padLeft(4).padRight(4).width(140f).wrap().get(); label.update(() -> { if(counter[0] < 0 || (counter[0] += Time.delta) >= period){ - String text = s.isobj ? PrintI.toString(s.objval) : Math.abs(s.numval - (long)(s.numval+0.5)) < 0.00001 ? (long)(s.numval+0.5) + "" : s.numval + ""; + String text = s.isobj ? PrintI.toString(s.objval) : Math.abs(s.numval - Math.round(s.numval)) < 0.00001 ? Math.round(s.numval) + "" : s.numval + ""; if(!label.textEquals(text)){ label.setText(text); if(counter[0] >= 0f){