DecimalFormat
can be used to format numbers with patterns like ###,###.###
.Here's how you can use it:
var formatter = new DecimalFormat("###,###.###");
System.out.println(formatter.format(123456789.1234)); // 123,456,789.123
System.out.println(formatter.format(0.1234)); // 0.123