I need to format a decimal value into a string where I always display at lease 2 decimals and at most 4.
So for example
\"34.49596\" would be \"34.4
Yes you can do it with String.format:
String.format
String result = String.format("%.2f", 10.0 / 3.0); // result: "3.33" result = String.format("%.3f", 2.5); // result: "2.500"