From 5cafd876089280d6b963a630bd6552c6a54611b5 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Wed, 21 Sep 2022 01:57:48 +0200 Subject: [PATCH] Use double-precision diameter labels --- .../dialogs/motor/thrustcurve/MotorFilterPanel.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java index 42907a5d3..5276daa8d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorFilterPanel.java @@ -69,9 +69,14 @@ public abstract class MotorFilterPanel extends JPanel { for( int i = 0; i < motorDiameters.length; i++ ) { // Round the labels, because for imperial units, the labels can otherwise overlap double diam = unit.toUnit(motorDiameters[i]); - diam = unit.round(diam); - diam = unit.fromUnit(diam); - diameterLabels.put( i, new JLabel(unit.toString(diam))); + double diamRounded = unit.round(diam * 10) / 10; // 10 multiplication for 2-decimal precision + diam = unit.fromUnit(diamRounded); + String formatted = unit.toString(diam); + // Remove the leading zero for numbers between 0 and 1 + if (diamRounded > 0 && diamRounded < 1) { + formatted = formatted.substring(1); + } + diameterLabels.put( i, new JLabel(formatted)); } diameterLabels.get( motorDiameters.length-1).setText("+"); }