Properly rounding numbers for display (#10354)
All checks were successful
Validate Gradle Wrapper / Validation (push) Successful in 24s
Tests / runPush (push) Successful in 24m0s

This commit is contained in:
Cardillan 2024-11-29 17:59:17 +01:00 committed by GitHub
parent 7e3572df51
commit a3110fde21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -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 + "");
}

View File

@ -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){