Some fixes for floating point formatting

This commit is contained in:
Frank 2022-07-15 10:40:02 +02:00
parent ef38a9888b
commit 5637de6ac6
2 changed files with 23 additions and 2 deletions

View file

@ -52,7 +52,7 @@ public class Slider<N extends Number> extends AbstractSliderButton {
this.minValue = minValue;
this.maxValue = maxValue;
this.onChange = onChange;
this.updateMessage();
}
@ -81,6 +81,18 @@ public class Slider<N extends Number> extends AbstractSliderButton {
}
protected String valueToString(N value) {
if (minValue instanceof Float || minValue instanceof Double) {
double v = value.doubleValue();
double m = maxValue.doubleValue();
if (m > 1000)
return "" + (int) v;
if (m > 100)
return String.format("%.1f", v);
if (m > 10)
return String.format("%.2f", v);
return String.format("%.4f", v);
}
return "" + value;
}